Speeding up a lambda function

0

Hi,

I currently have a lambda function that's using primarily the modules NLTK and LightGBM to do some webscraping and sentiment analysis. However, when I test it, it takes about 7 seconds to run. But when I test it immediately again, it only takes under a second, even with a different website. I'm wondering why this is the case and if it's possible to make all tests run this fast, because it's making my project run pretty slow.

hczhang
질문됨 10달 전231회 조회
2개 답변
1

You should consider provisioned concurrency option for lambda to minimize the latency and cold start. Make sure it has enough memory allocated to it.

Here is the blog post, which is very thorough and have detailed explanation about, how does it work and how it would help you to speed up operation.

To your question, why it takes less time second time, here is the verbiage from above mentioned blog post for your quick reference:

  After the execution completes, the execution environment is frozen. To improve resource management and performance, the Lambda service retains the execution environment for a non-deterministic period of time. During this time, if another request arrives for the same function, the service may reuse the environment. This second request typically finishes more quickly, since the execution environment already exists and it’s not necessary to download the code and run the initialization code. This is called a “warm start”.

For java applications, you can consider snapstart option, here is the blog post for same.

References:

Configuring Provisioned Concurrency

Hope this helps, feel free to comment here if there are additional questions.

Abhishek

profile pictureAWS
전문가
답변함 10달 전
profile pictureAWS
전문가
검토됨 10달 전
  • Do you have any questions further?

  • I reserved concurrency for my function which sped it up a lot. Thanks.

0

What you are experiencing is called Cold Start. This happens every time we create a new execution environment to run your function. After the invocation finishes, we keep it around, and if a new invocation happens, we reuse the execution environment, and this is a warm start.

There are different things that can be done to reduce the cold start duration. One of them is to reduce the Lambda package size (may not be possible in your case). You can find more optimization options here.

Note, cold start are most often not an issue. For instance, if your function is invoked asynchronously, cold start time usually doesn't matter. It mainly matters when you have a user making a synchronous API call. In this case, if really needed, you can use provisioned concurrency to initialize execution environments up front. Note that this will incur additional cost.

profile pictureAWS
전문가
Uri
답변함 10달 전

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

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

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

관련 콘텐츠