Java 2.x - High execution time of lambda

0

My lambda takes a long time to do the first operation with an aws client. For example I am performing a query on the index through the dynamoDB client and the first execution takes 2 seconds, while in subsequent executions on the same lambda environment the query is executed in 100 milliseconds. The DynamoDB client is inizialized outside of the Lambda handler method. Why my first execution takes so long?

已提問 1 年前檢視次數 257 次
1 個回答
1

First execution will always take longer than subsequent requests. Mostly it has to do with the client initialization, regardless if its outside of the Lambda handler the first request must initialize the client. Moreover, DynamoDB makes use of internal metadata caching, which also needs to be populated and can add a couple of extra hops to your first request which increases your overall latency slightly.

You can perhaps use the recently released Common Runtime (CRT) HTTP client for the SDK which boasts the following improvements:

  • faster SDK startup time
  • smaller memory footprint
  • reduced latency time
  • connection health management
  • DNS load balancing
profile pictureAWS
專家
已回答 1 年前
  • You might also consider SnapStart but it will require using a different Java version.

  • Thank you Brettski-AWS, but I am using Java 8.

  • Thank you Leeroy Hannigan, but i need a synchronous client.

  • Using CRT is only a suggestion, the rest of my answer still stands. You cannot avoid client initialization unless you initialize it in advance. Likewise, you cannot avoid DynamoDB metadata cache misses if you have not been sending requests frequently.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南