开发者

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

Why is my RPC total going up?

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

Smart spot

Why is my RPC total going up?

As you can see the API usage is do开发者_StackOverflow社区ubled 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

Why is my RPC total going up?

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.


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.


Ahhhh. It is very helpful when posting about app engine to mention if your results are on the dev server or in production. The dev server does not have the same performance characteristics as the production servers, so it is not the best way to profile your application. In fact, I believe that indexes are not used at all, and that the dev server is single threaded, so you can't handle concurrent requests with it. In fact, if your app makes calls to itself, it won't work at all!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜