简体   繁体   English

AWS Gateway永远需要调用lambda函数

[英]AWS Gateway takes forever to call the lambda function

I set up some logs to check the incoming requests for an endpoint. 我设置了一些日志以检查端点的传入请求。 I found out Gateway takes at least 10s to call the lambda function: 我发现Gateway至少需要10秒钟才能调用lambda函数:

2016-03-05 21:32:19 UTC+1 Starting execution for request: 5b673e5b-e311-11e5-bf9b-33cf30c5916a
2016-03-05 21:32:19 UTC+1 Method request path: {}
2016-03-05 21:32:19 UTC+1 Method request query string: {}
2016-03-05 21:32:19 UTC+1 Method request headers:
2016-03-05 21:32:19 UTC+1 Method request body before transformations:
2016-03-05 21:32:19 UTC+1 Endpoint request URI:
2016-03-05 21:32:19 UTC+1 Endpoint request headers:
2016-03-05 21:32:19 UTC+1 Endpoint request body after transformations:
### THE CALL IS HERE ###
2016-03-05 21:32:30 UTC+1 Endpoint response body before transformations:
2016-03-05 21:32:30 UTC+1 Endpoint response headers:
2016-03-05 21:32:30 UTC+1 Method response body after transformations:
2016-03-05 21:32:30 UTC+1 Method response headers:
2016-03-05 21:32:30 UTC+1 Successfully completed execution
2016-03-05 21:32:30 UTC+1 Method completed with status: 200

And the logs from the lambda function: 以及来自lambda函数的日志:

2016-03-05 21:32:29 UTC+1 START RequestId: 5b678c7a-e311-11e5-a92e-7109901c2d08 Version: 65 
2016-03-05 21:32:30 UTC+1 END RequestId: 5b678c7a-e311-11e5-a92e-7109901c2d08 
2016-03-05 21:32:30 UTC+1 REPORT RequestId: 5b678c7a-e311-11e5-a92e-7109901c2d08  Duration: 699.25 ms Billed Duration: 700 ms Memory Size: 128 MB Max Memory Used: 41 MB

Is that normal? 那是正常的吗? How can I speed this up? 我怎样才能加快速度?

Thanks. 谢谢。

This is not typical, however you might see a small fraction of requests taking much longer than average due to Lambda function initialization, ie "cold start" behavior. 这不是典型的情况,但是由于Lambda函数初始化(即“冷启动”行为),您可能会看到一小部分请求花费的时间比平均时间长得多。 You're not billed for the initialization time so you don't see the total time in your Lambda logs. 您无需为初始化时间付费,因此您不会在Lambda日志中看到总时间。

Best advice to avoid these high worst-case latencies: 避免这些高延迟情况的最佳建议:

  • Ensure your Lambda function has enough memory allocated 确保您的Lambda函数分配了足够的内存
  • Ensure your Lambda function is receiving consistent traffic in order to keep the function "warm" 确保您的Lambda函数接收一致的流量,以使该函数保持“温暖”状态

If you follow this advice, and still see consistent latencies in this range over many requests, please let us know. 如果您遵循此建议,但仍然在许多请求中看到此范围内的一致延迟,请告诉我们。

Cheers, Ryan 干杯,瑞安

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

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