简体   繁体   English

AWS Java Lambda JVM实例

[英]AWS Java Lambda JVM instances

Let's assume I have one AWS lambda Function 假设我有一个AWS lambda函数

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

Let's say lambdaFunction1 is triggered on any new message in SNS Topic. 假设lambdaFunction1在SNS Topic中的任何新消息上触发。 How many JVM instances will be triggered for 10 SNS messages? 10条SNS消息将触发多少个JVM实例?

Does AWS lambda execute each lambda in it's own JVM or it re-utilizes same JVM instances. AWS lambda是在其自己的JVM中执行每个lambda还是重新利用相同的JVM实例。

Quoting https://aws.amazon.com/de/blogs/compute/container-reuse-in-lambda/ 引用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. Lambda可能会重新创建一个新容器,在这种情况下,体验就如上所述。 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. 但是,如果您没有更改代码并且没有花费太多时间,Lambda可能会重用以前的容器。 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. 这为双方都提供了一些性能优势:Lambda可以跳过nodejs语言的初始化,而您可以跳过代码中的初始化。 Files that you wrote to /tmp last time around will still be there if the sandbox gets reused. 如果沙箱被重用,您上次写入/ tmp的文件将仍然存在。

Remember, you can't depend on a container being reused, since it's Lambda's prerogative to create a new one instead. 请记住,您不能依赖于被重用的容器,因为创建新的容器是Lambda的特权。

As said: You can not depend on the container being reused but there is a good chance when AWS deems it a performance gain. 如前所述:您不能依赖于被重用的容器,但是当AWS认为它可以提高性能时,这是一个很好的机会。

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. 或更简单地说:AWS可能知道该怎么做才能使Lambda尽可能高效,因此您可能不必真正考虑这一点。

Also while this blog is aimed at Node.js AWS seems to do something similar for Java based on this post by them. 同样,尽管此博客针对Node.js,但基于他们的这篇文章,AWS似乎也为Java做过类似的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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