2016-03-05 66 views
0

我設置了一些日誌來檢查端點的傳入請求。 我發現網關至少需要10秒來調用lambda函數:AWS網關需要永久調用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 

是正常嗎?我如何加快速度?

謝謝。

+0

這是可重複的嗎?總是或間歇地? –

+0

聽起來像是用AWS支持開票的東西 – Max

+0

是的,它是可重複的,並不總是10秒。有時候4. – Erem

回答

2

這不是典型的,但是由於Lambda函數初始化,即「冷啓動」行爲,您可能會看到一小部分請求比平均時間長得多。您沒有爲初始化時間收費,所以您沒有看到Lambda日誌中的總時間。

最好的建議,以避免這些高最壞情況下的延遲:

  • 確保您的lambda表達式有足夠的內存分配
  • 確保您的拉姆達函數接收順序一致流量,以保持功能「暖」

如果您遵循此建議,並且在許多請求中仍然可以看到此範圍內的一致性延遲,請告訴我們。

乾杯, 瑞安