Control Lambda Compute for large traffic

0

For my RestApi, I have used lambda as backend integration. My Lambda existing concurrency is 1000. For load testing , I set parameters as 1000 concurrent users and 500 users/ second on locust. Lambda timeout is 3 min. If I made 40/50 requests in 1 minute for single user , lambda duration per API hit is 500 ms or less. But while load testing, I made 100 K requests. Out of them about 50 K requests' responses were internal server error and other throttling.

While I check lambda logs in cloudwatch , many requests were of 51000 millisecond. Due to this large lambda duration, lambda total compute increased much. Since for very low traffic, lambda duration is of 500 ms, how can I control lambda duration to 500 ms or less for large number of requests during large traffic.

已提问 2 年前248 查看次数
1 回答
0
已接受的回答

The duration of each function invocation should not be affected by the number of total invocations, unless the function itself is using some other service, e.g., a database, that can't handle the load and takes longer to respond, and therefore making the total function duration higher. Could it be that that is your situation?

To analyze where the higher duration is coming from I would recommend to use X-Ray.

profile pictureAWS
专家
Uri
已回答 2 年前
profile picture
专家
已审核 1 个月前
  • I have used MongoDb where max pool limit is 500 . There was db connection max pool reached issue during execution. Does limiting lambda timeout to 2 sec solve the problem since all requests are of 500 ms in normal traffic?

    For every request , new db connection is initiated. Can we use already connected database to other requests? I have used mangum python package for handler

  • You should create your connection to the database outside the function handler so that a single connection will be used for all invocations of the function in the same execution environment (an execution environment handles a single request at a time as is reused by subsequent invocations). Do not close the connection. The connection will be closed automatically by the database after the execution environment will be destroyed.

    Limiting the function to 2 seconds might be problematic if it takes MongoDB to answer more than 2 seconds.

    You should not use a connection pool inside Lambda Lambda function has no shared memory between different execution environments, so a pool will not help.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则