I have a few AppEngine operations that take more time than expected, so I've been looking at the trace logs on the GAE console to get some insights.
One of them consists in a simple query to sort entities, such as
(data, cursor, more) = query.order(-cls.created).fetch_page(RESULTS_PER_PAGE, start_cursor=cursor)
but according to the logs, and if I understand the trace correctly (screenshot below), the operation run 2 queries: one to get the data (RunQuery), one to find if there's more data (Next). Neither take too much time, but there's a 600ms delay between both.
I'm wondering why this delay both is too long? I've seen some issues about Next() where queries took longer (How do I prevent application calling datastore_v3.next() when calling get_multi?), but the time for Next() in my case is very minimal. The bottleneck seems to be the time between both. This happens in lots of cases - the previous NDB query is just an example.
So:
- Can I avoid calls to Next() or
- Can I minimize the delay between RunQuery and Next()
I'm using a standard instance, and don't have any specific setup in my app.yaml file, besides an inbound warmup.