Question

Please Help me ..

How to Implement web site hit COUNTER USING APPENGINE java JDO...(Mutliple users hits at a time)

I tried a simple jdo class with count varible

and increment function to increase the counter but in the case of muliple user the count is not working as expected.

Was it helpful?

Solution 2

Writing the updated count value is fairly slow, so you are probably suffering from race conditions and eventual consistency problems. Depending on your software, the Datastore may not be able to perform more than about one write per second.

The first thing to add is a Sharding Counter to scale up your concurrent count capacity.

The second thing is to move the counter update code into a Push Queue so that the web page response code is not delayed by the hit counter code.

OTHER TIPS

This is not a trivial task. There are two factors in play when you want to change a shared piece of data (a counter) in GAE:

  1. Datastore limits the update rate per entity (actually entity group) to about 1 update/s. You need to divide (shard) a counter into multiple entities: see sharding counters.

  2. You need to change counter transactionally to make sure it is not overwritten by parallel requests.

Transactional example:

PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
  tx.begin();
  // here you should load the counter entity, increase it and then save it
  tx.commit();
} finally {
  if (tx.isActive()) {
    tx.rollback();
  }
  pm.close();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top