Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6558553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:12:47+00:00 2026-05-25T13:12:47+00:00

When trying to optimize a query for getting store records based on location, I

  • 0

When trying to optimize a query for getting store records based on location, I dumped in to something strange (I think), getting large dataset takes ALOT of cpu time.

Basically I have > 1000 records that need to be iterated over to find stores within the 3000m of a users position, and I got quite high numbers in the admin console.

This lead to some datastore testing that resulted in some interesting numbers for getting 1000 records.

I have 6 tests methods to I ran separately and took the cpu time from the admin console and appstats and it resulted in this (in production):

    r = db.GqlQuery("SELECT __key__ FROM StoreRecords").fetch(1000)
    # appstats: real=120ms cpu=182ms api=845ms
    # admin console: 459ms 1040cpu_ms 845api_cpu_ms

    r = db.GqlQuery("SELECT __key__ FROM StoreRecords").fetch(100)
    # appstats: real=21ms cpu=45ms api=95ms
    # admin console: 322ms 134cpu_ms 95api_cpu_ms

    r = db.GqlQuery("SELECT * FROM StoreRecords").fetch(1000)
    # appstats: real=1208ms cpu=1979ms api=9179ms
    # admin console: 1233ms 10054cpu_ms 9179api_cpu_ms

    r = db.GqlQuery("SELECT * FROM StoreRecords").fetch(100)
    # appstats: real=57ms cpu=82ms api=929ms
    # admin console: 81ms 1006cpu_ms 929api_cpu_ms

    r = model.StoreRecords.all().fetch(1000)
    # appstats: real=869ms cpu=1526ms api=9179ms
    # admin console: 1061ms 9956cpu_ms 9179api_cpu_ms

    r = model.StoreRecords.all().fetch(100)
    # appstats: real=74ms cpu=86ms api=929ms
    # admin console: 97ms 1025cpu_ms 929api_cpu_ms

Here I only take at the most a 1000 records, but will need to fetch all (about 4-5000).

My questions are:

  1. Should a fetch of a 1000 records really take almost 20 (10054cpu_ms + 9179api_cpu_ms) seconds ?
  2. Why are there differences between the appstas and admin console times? What is calculated against my quota?

One could easily get around this by pushing the fetched records in to memcache as a protobuf. But I’m curios about the high usage and the differences in time between appstas and admin console.

Bonus question:
How come that fetching 1000 records always result in 9179api_cpu_ms?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:12:48+00:00Added an answer on May 25, 2026 at 1:12 pm

    Why is it surprising that retrieving a lot of records takes a lot of resources? This is an O(n) process, and you really shouldn’t be doing this on a per-request basis. To answer your questions in order:

    1. How much CPU time it uses depends on the nature of the records, but this result isn’t surprising. Note that it’s nearly 20 CPU seconds, not wallclock seconds. Also note that when the new billing model rolls out you’ll be charged for datastore operations and instance hours, which is what you should be optimising for.
    2. The admin console shows the authoritative figures that you’re billed based on. The appstats figures are lower because they only count the time spent during API calls, not the time spent executing your own code.

    If your set of records is small and fairly static, you should cache them in instance memory rather than fetching them each time or storing them in memcache. If they’re larger and dynamic, you should use something like GeoModel so you can do geographical queries and fetch only the relevant records.

    Fetching 1000 records always takes the same amount of API CPU time because it’s how datastore access costs are represented – it’s not actually time taken. The new model fixes this by breaking it out into separate billable operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to optimize a query that does something like this: SELECT ...
I've trying to optimize a query on MySQL that takes around 15-20 seconds to
I'm trying to optimize query performance and have had to resort to using optimizer
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I'm having trouble trying to optimize the following query for sql server 2005. Does
I am trying to optimize this query. It is not slow for now but
Hey guys, trying to optimize this query to solve a duplicate user issue: SELECT
I am trying to optimize a sql query which is using order by clause.
We are trying to optimize some of our queries. One query is doing the
I have a browse category query that im trying to optimize. Im ending up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.