Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit the consuming rate from a topic?

Has anyone else solved the following problem?
I have SNS topic filled with events from S3 and there is Lambda function which is subscribed on this topic and when thousand of events are put to this topic, lambda function is throttled because of exceeding the limit of concurrency.
I don't want to request a limit increase for concurrent executions but I would decrease concurrent consuming from the topic, but I didn't find information how to do it. Thanks.

like image 544
nikolayandr Avatar asked Nov 06 '16 20:11

nikolayandr


People also ask

How do you define rate limits?

Rate limiting is a strategy for limiting network traffic. It puts a cap on how often someone can repeat an action within a certain timeframe – for instance, trying to log in to an account.

Does SNS have a limit?

Amazon SNS limitsBoth subscribe and unsubscribe transactions are limited to 100 transactions per second (per AWS account). The Publish API, the core API for publishing SNS messages, will be throttled at the following levels: 30,000 calls/second in the us-east-1 region.

How many lambda functions can run at once?

The default concurrency limit per AWS Region is 1,000 invocations at any given time. The default burst concurrency quota per Region is between 500 and 3,000, which varies per Region. There is no maximum concurrency limit for Lambda functions.


1 Answers

A couple of options regarding SNS:

1) SNS Maximum Receive Rate

Set the SNS Maximum Receive Rate. This will throttle the SNS messages sent to a subscriber, but may not be a great option if you have so many messages that they will be discarded before they can be processed. From the documentation:

You can set the maximum number of messages per second that Amazon SNS sends to a subscribed endpoint by setting the Maximum receive rate setting. Amazon SNS holds messages that are awaiting delivery for up to an hour. Messages held for more than an hour are discarded.

If you're only getting thousands of events at a time, setting the Maximum Receive Rate to Lambda's default concurrent execution limit of '100' might be worth a try.

As @kndrk notes, this throttling is currently only available for HTTP/HTTPS subscribers to the SNS topic. To work around this, you can expose your lambda function via AWS API Gateway and subscribe that endpoint to the SNS topic, rather than the lambda function directly.

2) Process from SQS

Subscribe an SQS queue to the SNS topic and process messages from the queue, rather than directly from the sns topic. A single invokation of SQS ReceiveMessage can only handle 10 messages at a time, so that may be easier for you to throttle.


It is also worth noting that you can publish S3 Events directly to AWS Lambda.

like image 128
Anthony Neace Avatar answered Sep 22 '22 09:09

Anthony Neace