简体   繁体   中英

AWS Java Lambda JVM instances

Let's assume I have one AWS lambda Function

**String lambdaFunction1() {
//some processing 
}**

Let's say lambdaFunction1 is triggered on any new message in SNS Topic. How many JVM instances will be triggered for 10 SNS messages?

Does AWS lambda execute each lambda in it's own JVM or it re-utilizes same JVM instances.

Quoting https://aws.amazon.com/de/blogs/compute/container-reuse-in-lambda/

Let's say your function finishes, and some time passes, then you call it again. Lambda may create a new container all over again, in which case the experience is just as described above. This will be the case for certain if you change your code.

However, if you haven't changed the code and not too much time has gone by, Lambda may reuse the previous container. This offers some performance advantages to both parties: Lambda gets to skip the nodejs language initialization, and you get to skip initialization in your code. Files that you wrote to /tmp last time around will still be there if the sandbox gets reused.

Remember, you can't depend on a container being reused, since it's Lambda's prerogative to create a new one instead.

As said: You can not depend on the container being reused but there is a good chance when AWS deems it a performance gain.

Or to keep it simpler: AWS probably knows what to do to get your Lambdas as efficient as possible so you should not really overthink this probably.

Also while this blog is aimed at Node.js AWS seems to do something similar for Java based on this post by them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM