Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my RPC total going up?

I'm Trying to optimize my code, and I got into a problem I don't quite understand. On every page of my web app, there will be a list of notifications much like Facebook's new ticker. So, on every request, I run this code in the beggining:

notification_query = db.Query(Ticker, keys_only=True)\
   .filter('friends =',self.current_user.key().name())
self._notifications_future = notification_query.run()

Then, where I find a good spot, I call the middle function which is:

notification_keys = [future.parent() for future in self._notifications_future]
self._notifications = db.get_async(notification_keys)

Finally I fetch them all at the end:

context.update({'notifications': self._notifications.get_result() })

Every thing works great except for this: If I call the middle function in the end of the request's function, I get this:

Dumb spot

Dumb spot

And If I call it in what I think is an optimized spot, I get this:

Smart spot

Smart spot

As you can see the API usage is doubled by making this "optimization". What is going on here?

Call number 2, is the first snippet in both cases. Call number 12 in dumb spot is the second snippet, and call number 12 in the smart spot is the second snippet. This last switch, has nothing to do with the problem, I've tested it.

pd: Does google charge me for time the query is "idle"?

UPDATE

The problem seems to be just in the dev_server, when I tried the same example (smart version) on appspot, I got this:

Queries on appspot

appspot

Here everything works as expected, things that get called with run() or get_async() don't block other stuff. As I said the issue is only in dev_server. Still it would be nice to see this feature working on localhost, for more effective profiling.

like image 898
fceruti Avatar asked Oct 10 '22 18:10

fceruti


1 Answers

In addition to Peter's note, you should bear in mind that Appstats has no way to know when an asynchronous request actually completes, except when you fetch the result. As a result, even fast calls will look slow if you take a long time to request the result.

like image 123
Nick Johnson Avatar answered Oct 12 '22 09:10

Nick Johnson