I've read a lot of the GAE articles on counters and this pesky write limit in GAE. I've seen solutions with sharding, cron tasks, memcache, etc. Then I learned enough about java threads to be able to ask the question:
Q: Can we implement a counter in servlet threads using concurrency / servlet static varibales?
This would have the added benefit of fewer writes to the datastore and memcache (cost the same $), and remove the cron requirement as the last servlet in a series of fast counter hits would update the datastore.
I don't know enough about concurrent programming to come up with a solution, but I imagine something with static servlet variables, maybe "atomic-integers" and a last-update flag to enable checking if THIS servlet was the last servlet to update the static var, in the last 200ms, thus triggering a save to the datastore.
// Servlet gets a hit
// static var counter++
// Checks last datastore save time of the static var, if longer than 200ms
// save to datastore & save "last update time"
// If shorter than 200 ms ago, let the next servlet call update the datastore
Can this be done? Any proposals? Mucho appreciado on your thoughts.