title: Django + Gunicorn on Google Cloud Run, how are different parameters of Gunicorn and GCR related?
body: <p>For deploying a Django web app to GCR, I would like to understand the relationships between various autoscaling related parameters of Gunicorn and GCR.</p>
  <p>Gunicorn has flags like:</p>
  <ul>
  <li>workers</li>
  <li>threads</li>
  <li>timeout</li>
  </ul>
  <p>Google Cloud Run has these configuration options:</p>
  <ul>
  <li>CPU limit</li>
  <li>Min instances</li>
  <li>Max instances</li>
  <li>Concurrency</li>
  </ul>
  <p>My understanding so far:</p>
  <ul>
  <li>Number of workers set in Gunicorn should match the CPU limit of GCR.</li>
  <li>We set <code>timeout</code> to 0 in Gunicorn to allow GCP autoscale the GCR instance.</li>
  <li>GCP will always keep some instances alive, this number is <code>Min instances</code>.</li>
  <li>When more traffic comes, GCP will autoscale up to a certain number, this number is <code>Max instances</code>.</li>
  </ul>
  <p>I want to know the role of threads (Gunicorn) and concurrency (GCR) in autoscaling. More specifically:</p>
  <ul>
  <li><strong>How does the number of thread in Gunicorn affect autoscaling?</strong></li>
  </ul>
  <p>I think This should not affect autoscaling at all. They are useful for background tasks such as file operations, making async calls etc.</p>
  <ul>
  <li><strong>How does the Concurrency setting of GCR affect autoscaling?</strong></li>
  </ul>
  <p>If number or workers is set to 1, then a particular instance should be able to handle only one request at a time. So setting this value to anything more than 1 does not help. In fact, We should set CPU limit, concurrency, workers these three to match each other. Please let me know if this is correct.</p>
  <p>Edit 1:
  Adding some details in response to John Hanley's commment.</p>
  <ul>
  <li>We expect to have up to 100 req/s. This is based on what we've seen in GCP console. If our business grows we'll get more traffic. So I would like to understand how the final decision changes if we're to expect say 200 or 500 req/s.</li>
  <li>We expect requests to arrive in bursts. Users are groups of people who perform some activities on our web app during a given time window. There can be only one such event on a given day, but the event will see 1000 or more users using our services for a 30 minute window. On busy days, we can have multiple events, some of them may overlap. The service will be idle outside of the event times.</li>
  <li>How many simultaneous requests can a cloud run instance handle? I am trying to understand this one myself. Without cloud run, I could've deployed this with x number of workers and then the answer would've been x. But with cloud run, I don't know if the number of gunicorn workers have the same meaning.</li>
  </ul>
  <p>Edit 2: more details.</p>
  <ul>
  <li>The application is stateless.</li>
  <li>The web app reads and writes to DB.</li>
  </ul>