Concurrent requests in Appengine Python

Official appengine documentation says that if we set threadsafe property to true in app.yaml then appengine will server concurrent requests.

Official link: https://developers.google.com/appengine/docs/python/python27/newin27#Concurrent_Requests

  • Does it mean application will be faster (than 2.5) if we have threadsafe property to true? Official documentation/blog says so but i am looking for real world experiences.

  • At highlevel, How does it work internally? Will our application be initialized and spawn a new theread for each request?


  • You still only have one thread per request - you can't spawn.

    With threadsafe off, Appengine will only route one request to an instance. So if the number of requests per second times the time to handle a request approaches one, Appengine will spin up a new instance to handle them. This cost money. With threadsafe on, Appengine can route more than one request to an instance.

    Whether this helps you or not depends on your app and your traffic:

  • First, calculate inbound request per second / average latency. If this is well under one, threadsafe won't make much difference either way.
  • Examine your app to find out how much time it spends waiting on APIs (datastore or URL fetch for instance). If this is a large proportion, then threadsafe will help keep your instance count down. If not, it won't help much.
  • The simple rule is switch threadsafe on unless your app is very processing-intensive (little API waiting).


  • It doesn't mean that your application will become faster, the request are still served from a single thread.
  • When the application is thread safe each instance can now spawns multiple threads each thread will serve a request as apposed to the non thread safe where each instance has a single thread serving requests.

  • Python 2.5 is still a bit faster, on a per-request basis, than Python 2.7. That's partially due to how mature each is. App Engine uses different mechanisms to support each of them. The win with Python 2.7's is its ability to support parallel requests rather than spinning up new instances at a rate that would be required by Python 2.5 to handle load spikes.

    The "how does it work internally" question is one that you're probably not going to get an answer for here, but there are some talks from past year's Google I/O that hint at what we do and why. Search youtube.com for "app engine".

    链接地址: http://www.djcxy.com/p/91616.html

    上一篇: Python Google App Engine:发送邮件错误

    下一篇: Appengine Python中的并发请求