How many Datastore reads consume each Fetch, Count and Query operations?

前端 未结 2 1570
闹比i
闹比i 2020-12-25 11:20

I\'m reading on Google App Engine groups many users (Fig1, Fig2, Fig3) that can\'t figure out where the high number of Datastore reads in their billing reports come from.

2条回答
  •  无人及你
    2020-12-25 12:09

    See http://code.google.com/appengine/docs/billing.html#Billable_Resource_Unit_Cost . A query costs you 1 read plus 1 read for each entity returned. "Returned" includes entities skipped by offset or count. So that is 1001 reads for each of these:

    Example.all(keys_only = True).filter('bars=','spam').count() 
    Example.all().count(1000)
    Example.all().fetch(1000)
    Example.all().fetch(1000, offset=500)
    

    For these, the number of reads charged is 1 plus the number of entities that match the filters:

    Example.all().filter('bars=','spam').filter('bars=','fu').fetch()
    Example.all().filter('foo>=', filtr).filter('foo<', filtr+ u'\ufffd').fetch()
    

    Instead of using count you should consider storing the count in the datastore, sharded if you need to update the count more than once a second. http://code.google.com/appengine/articles/sharding_counters.html

    Whenever possible you should use cursors instead of an offset.

提交回复
热议问题