It can be, but there's a fundamental tradeoff to doing so: you'd be
transacting on every single count increment. It's just a matter of how much
volatility you can accept:

1. Most volatile: Only use Memcache and INCR
2. Still volatile but generally okay: Use Memcache with INCR and periodic
flushing
3. Better with a minor race condition, mitigated by number of shards:
sharded counter
4. Best but expensive: transactional updates on each sharded counter

Something like pageview counts, for instance, may fall under #2, since you
just need a number that is good enough - as this number grows, you have a
higher margin of inaccuracy that you'd accept. For a counter that isn't
frequently incremented, you'd have to consider whether sharding the counter
is worthwhile.

On Fri, Mar 26, 2010 at 2:38 PM, jbdhl <[email protected]> wrote:

> Thanks. But using memcache would give me a somewhat "fragile" counter
> as it's memory-only. However, I stumbled upon Jeff Scudder's
> implementation of a sharded counter, which is exactly what I'm looking
> for. But... Shouldn't the code that 1) fetches a shard, and 2)
> increases it, be encapsulated in a transaction in order to prevent
> other users to make an update between 1) and 2)? Is his implementation
> really "thread safe"?
>
> The increment-code can be seen in
>  demos/shardedcounter/src/com/google/appengine/demos/shardedcounter/
> v3/ShardedCounter.java
> in the App Engine SDK.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>


-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to