开发者

What is the performance hit of enabling sessions on Google App Engine?

开发者 https://www.devze.com 2022-12-23 07:42 出处:网络
What is the performance hit of enabling sessions on the Google App Engine? I just turned on <sessions-enabled>true</sessions-enabled> in my Google App Engine app and now my requests are c

What is the performance hit of enabling sessions on the Google App Engine?

I just turned on <sessions-enabled>true</sessions-enabled> in my Google App Engine app and now my requests are consistently using 100 more ms of CPU time than before I enabled it. It also makes the user wait an additional 100ms for the server to respond on each request. This seems to be quite a significant cost, I'm not even calling getSession or using it in any way yet and it still adds this extra latency.

Is there s开发者_Go百科omething I can do to speed this up?

EDIT: Strangely the extra cpu time is gone now.


Each request using sessions is going to need to fetch the session data from either memcache (in the best case) or the datastore and then at the end of the request write session information to both the cache and the datastore. 100ms of added latency seems like a reasonable figure; obviously the actual latency for any given request will depend on whether there's a cache miss and the (highly fluctuating; see the app engine status page) latency for each API call.


2018 UPDATE

I know this question is kind of old, but I think it's worth mentioning that the performance of GAE sessions is currently even poorer. This is because the _expires property of _ah_SESSION is now being indexed. Having this index surely comes handy when querying for expired sessions. But there is a downside to this:

  1. storing an _ah_SESSION entity costs 4 writes instead of 2,
  2. since the _expires property contains monotonically increasing values, maintaining its index comes with a certain risk of contention, see this question for more details.

EDIT: Note that there is a somewhat widespread myth that _ah_SESSION entities are automatically rewritten after every request merely to update the expiration timestamp. But this is not true. According to the actual implementation of SessionManager, such rewrites are enforced only when the session is at least 25% expired. Which significantly reduces access to datastore. I am only mentioning this because I originally too believed this myth. :D

0

精彩评论

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