【问题标题】:AWS Gateway takes forever to call the lambda functionAWS Gateway 需要永远调用 lambda 函数
【发布时间】:2016-06-19 14:09:53
【问题描述】:

我设置了一些日志来检查端点的传入请求。 我发现 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

还有来自 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

这正常吗?如何加快速度?

谢谢。

【问题讨论】:

  • 这是可重复的吗?总是,还是断断续续?
  • 听起来像是用 AWS 支持开票
  • 是的,它是可重复的,而且并不总是 10 秒。有时 4.
  • 您愿意分享您的 Lambda 函数的基础架构吗?它是否访问任何其他服务?
  • 当然,这是一个 node.js 集成。它调用 slack API 并使用 dynamodb 存储一些数据。

标签: node.js amazon-web-services aws-api-gateway aws-lambda


【解决方案1】:

这并不典型,但是由于 Lambda 函数初始化,即“冷启动”行为,您可能会看到一小部分请求花费的时间比平均时间长得多。您无需为初始化时间付费,因此您不会在 Lambda 日志中看到总时间。

避免这些高最坏情况延迟的最佳建议:

  • 确保您的 Lambda 函数分配了足够的内存
  • 确保您的 Lambda 函数接收一致的流量,以保持函数“温暖”

如果您遵循此建议,并且在许多请求中仍然看到此范围内的一致延迟,请告诉我们。

干杯, 瑞恩

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-31
    • 2020-08-21
    • 2017-12-07
    • 2016-05-18
    • 2018-08-28
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    相关资源
    最近更新 更多