winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.9k stars 194 forks source link

Add consumer maxConcurrency prop to `cloud.Queue` #2282

Open flyingImer opened 1 year ago

flyingImer commented 1 year ago

Feature Spec

Max concurrency is a knob to control the pace of triggering consumers, concurrent cloud function invocations. It takes a num type (expecting an integer) for the max concurrency allowed for this particular consumer inflight function:

interface QueueAddConsumerProps extends FunctionProps {
  ...
  readonly maxConcurrency?: number;
}
myQueue.addConsumer(inflight (message: str) => { ... }, maxConcurrency: 100);

Use Cases

Cloud's infinite scalability is incredible. One part of the queue to function contract is to trigger X number of function invocations as soon as X number of messages put into the queue. However, dependencies of the cloud function may not be immediate infinite scalability ready, hence leading to undesired brownouts.

Another piece of the queue to function contract is the asynchronous: queue absorbs unpredictable real-time traffic ups and downs, letting consumer side complete the work asynchronously. So having this knob makes the handling more predictable.

Side note: this prop is tricky, as I also see it can be on the ops (non-function) side. In that sense, it should not be part of the SDK spec.

Implementation Notes

AWS: https://aws.amazon.com/blogs/compute/introducing-maximum-concurrency-of-aws-lambda-functions-when-using-amazon-sqs-as-an-event-source/ Azure: https://learn.microsoft.com/en-us/azure/azure-functions/functions-concurrency GCP: https://cloud.google.com/functions/docs/configuring/concurrency

Component

SDK

Community Notes

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 4 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 1 month ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!