4
votes

Using google cloud functions, is there a way to manage execution concurrency the way AWS Lambda is doing? (https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html)

My intent is to design a function that consumes a file of tasks and publish those tasks to a work queue (pub/sub). I want to have a function that consumes tasks from the work queue (pub/sub) and execute the task.

The above could result in a large number of almost concurrent execution. My dowstream consumer service is slow and cannot consume many concurrent requests at a time. In all likelyhood, it would return HTTP 429 response to try to slow down the producer.

Is there a way to limit the concurrency for a given Google Cloud functions the way it is possible to do it using AWS?

4

4 Answers

4
votes

This functionality is not available for Google Cloud Functions. Instead, since you are asking to handle the pace at which the system will open concurrent tasks, Task Queues is the solution.

Push queues dispatch requests at a reliable, steady rate. They guarantee reliable task execution. Because you can control the rate at which tasks are sent from the queue, you can control the workers' scaling behavior and hence your costs.

In your case, you can control the rate at which the downstream consumer service is called.

4
votes

This is now possible with the current gcloud beta! You can set a max that can run at once:

gcloud beta functions deploy FUNCTION_NAME --max-instances 10 FLAGS...

See docs https://cloud.google.com/functions/docs/max-instances

0
votes

You can set the number of "Function invocations per second" with quotas. It's documented here: https://cloud.google.com/functions/quotas#rate_limits

The documentation tells you how to increase it, but you can also decrease it to achieve the kind of throttling that you are looking for.

0
votes

You can control the pace at which cloud functions are triggered by controlling the triggers themselves. For example, if you have set "new file creation in a bucket" as trigger for your cloud function, then by controlling how many new files are created in that bucket you can manage concurrent execution. Such solutions are not perfect though because sometimes the cloud functions fails and get restart automatically (if you've configure your cloud function that way) without you having any control over it. In effect, the number of active instances of cloud functions will be sometimes more than you plan. What AWS is offering is a neat feature though.