How to read CPU cores available in Cloud Run environment?

Viewed 477

We see there are environmental variables available to read to get port/service/revision of a Cloud Run service.

In order to configure a multithreaded app, like gulp threads. How do you read how many cores are available?

Snippet:

# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
2 Answers

I believe this information is not available from within Cloud Run.

If you're looking to access multiple CPU cores in Cloud Run, you actually specify the number of cores during configuration. This is a constant value, so you don't need to check for it at runtime, so there is no feature to do so.

https://cloud.google.com/run/docs/configuring/cpu

By default Cloud Run container instances are allocated 1 CPU instance. You can change this number.

Related