Counting entities in particular range in Google Appengine Datastore -
Counting entities in particular range in Google Appengine Datastore -
i new google datastore. building simple app , want count number of entities satisfying particular criteria. obvious way first query entity , take count on result :
// applying query on "height" property of entity "person filter heightfilter = new filterpredicate("height", filteroperator.greater_than_or_equal, minheight); // utilize class query assemble query query q = new query("person").setfilter(heightfilter); // utilize preparedquery interface retrieve results preparedquery pq = datastore.prepare(q); // , count.
i wondering if best way carry out particular task. querying mechanism go through entire database of particular entity(person in case) , match 1 one. there improve way if need count , not entire entity?
the database not designed kind of queries, counting hard scale , you're encouraged come solution particular needs.
in case, have model keeps count you, , update every time add/remove person
. count fetch 1 entity , read count, perfect reads, fast , cheap.
the problem on writes, since want transactionally (to maintain accurate count) there might come time in application there more 1-5 updates per second, , transactions need retry , become bottleneck. 1 popular solution in stage utilize sharding counters, distribute counting process across multiple entities, , throughput scales up.
i advise maintain simple , move more advanced techniques when need it, maintain complexity under control. , never count, thought technology (non-sql) pay cost upfront, on writing, reads fast , efficient possible.
google-app-engine gae-datastore datastore google-datastore
Comments
Post a Comment