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개 답변
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
전문가
답변함 일 년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠