sharding counters in google app engine -



sharding counters in google app engine -

hi guys new google app engine, can u guys explain below code, why counter param used , declare parameters. have no source , helpless. eager larn concept, help me guys...

import pmf; import java.util.list; import java.util.random; import javax.jdo.persistencemanager; import javax.jdo.query; public class shardedcounter { private string countername; public shardedcounter(string countername) { this.countername = countername; } public string getcountername() { homecoming countername; } public int getcount() { int sum = 0; persistencemanager pm = pmf.get().getpersistencemanager(); seek { query shardsquery = pm.newquery(generalcountershard.class, "countername == nameparam"); shardsquery.declareparameters("string nameparam"); list<generalcountershard> shards = (list<generalcountershard>) shardsquery.execute(countername); if (shards != null && !shards.isempty()) { (generalcountershard current : shards) { sum += current.getcount(); } } } { pm.close(); } homecoming sum; }

not sure got code have great article here.

the thought behind sharded counters have counter has high "hit rate". lets need website has 100k's of users clicking "awesome" button on pictures. google app engine (gae) have storage scheme called datastore great storing kind of information. draw can updated 1 person @ time. if 5 people same photo @ exact same moment called "contention".

to avoid contention have shard counter. instead of 1 counter needs updated have many pool numbers grand total. (another analogy), need count number of vehicles on multi-lane high way, instead of 1 person trying count them have many each counting lane add together numbers @ end.

in practice (taken first link) have kind lets called "shardedcounter". has many shards (or people counting). when need increment counter phone call method 'increment' randomly chose 1 of shards increment add-on you. splitting request increment counter "evenly" between of shards. thereby reducing chance of contention. when need actual count loops through counters, adding them , returns actual count.

i hope makes sence, otherwise drop me comment , i'll best answer.

i'd note haven't done shard counters in java have many times in python

google-app-engine

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -