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

查看:49
本文介绍了每次都使用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天全站免登陆