Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 422
18bytes Avatar asked Jun 11 '12 09:06

18bytes


People also ask

How does Google handle multiple requests?

Any request can be routed to any instance, so consecutive requests from the same user are not necessarily sent to the same instance. An instance can handle multiple requests concurrently. The number of instances can be adjusted automatically as traffic changes.

What is the difference between app engine standard and flexible?

The standard environment can scale from zero instances up to thousands very quickly. In contrast, the flexible environment must have at least one instance running for each active version and can take longer to scale up in response to traffic. Standard environment uses a custom-designed autoscaling algorithm.

What is Gcloudignore?

gcloudignore file to tell gcloud which files should be not be uploaded for Cloud Build, without it, it defaults to .

What is app Engine request handler?

App Engine calls the handler script with a Request and waits for the script to return; all data written to the standard output stream is sent as the HTTP response. There are size limits that apply to the response you generate, and the response may be modified before it is returned to the client.


1 Answers

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:

  1. First, calculate inbound request per second / average latency. If this is well under one, threadsafe won't make much difference either way.
  2. 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).

like image 74
FoxyLad Avatar answered Oct 20 '22 06:10

FoxyLad