AWS Lambda 每次都加载库? [英] AWS Lambda loading libraries each time?

查看:23
本文介绍了AWS Lambda 每次都加载库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用 AWS Lambda 创建一个处理数据的 Python 函数.我需要加载一个重型模型来运行我的脚本(经过训练的 word2vec 模型),例如在我的计算机上完成它大约需要 5 分钟.但是一旦加载,函数的执行速度非常快.如果我使用 AWS Lambda,这个模型是只加载一次还是每次调用我的函数时都会加载?

谢谢,

解决方案

也许.

AWS Lambda 使用可重复使用的容器.因此,对于您的用例,如果 Lambda 函数发生在已经初始化的容器中,它会快速执行.不然会很慢.但是,您无法预测行为.

相关文档:

  1. 来自此处:

<块引用>

函数在创建或更新其代码或资源配置后第一次执行时,将创建一个具有适当资源的新容器来执行它,并将函数的代码加载到容器中.

>

假设你的函数完成了,一段时间过去了,然后你再次调用它.Lambda 可能会重新创建一个新的容器,在这种情况下,体验就像上面描述的那样.如果您更改代码,肯定会出现这种情况.但是,如果您没有更改代码并且时间不长,Lambda 可能会重用之前的容器.

请记住,您不能依赖容器的重复使用,因为 Lambda 有权创建一个新容器.

  1. 更多官方文档此处.

I am looking at AWS Lambda to create a Python function that would process data. I need to load a heavy model to run my script (trained word2vec model), it takes about 5 min to do it on my computer for example. But once it's loaded, the execution of the function is very fast. If I use AWS Lambda, will this model load only once or will it load each time I call my function ?

Thanks,

解决方案

Maybe.

AWS Lambda uses reusable containers. So, for your use case, the Lambda function will execute quickly if it happened in an already initialized container. It'll be slow otherwise. However, there is no way you can predict the behavior.

Relevant documentation:

  1. From here:

The first time a function executes after being created or having its code or resource configuration updated, a new container with the appropriate resources will be created to execute it, and the code for the function will be loaded into the container.

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.

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

  1. More official documentation here.

这篇关于AWS Lambda 每次都加载库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆