13. 更多的 Hook Handler
> Server Wakeup
• Server 若有閒置睡眠的機制,可能導致 API 的 timeout 不如預
期
• 如果
• API 設定 30 秒 timeout
• Server 起床要花 25 秒
• API Response 要 10 秒
• 那 API 可能會因為要等 Server 起床而 timeout
Run API
0
2
5
3
5
3
0
Server Wakeup
Timeout
Server Process
API
13
14. 更多的 Hook Handler
> Server Wakeup
• 在真的發 API 前
• 先 Ping Server
• 確保 Server 是醒著的之後
• 紀錄30分鐘內不再 Ping Server
• 真的發 API
*Success
*Error
*Finally
Send Request
Receive
Response
*Init
Ping
Receive
Response
14
15. 更多的 Hook Handler
> Server Wakeup
• 若有多個 API 同時發送
• 則將每個 API 都 Pending
• 直到確保 Server 是醒著的
• 再 async 去發 API
*Init
Ping
Receive
Response
API 1
API 2
…
15