# Optimize Node.js Performance with fork(2) - 吞吞 ###### tags: `jsdc2019` {%hackmd @JSDC-tw/2019-announcement %} > Start here ## Why we need - Runtime 冷啟動 50~100 ms - 嵌入式設備性能相當緊湊 - 函數運行時請求響應時間敏感 ## 嵌入式環境 - 多進程適應多使用場景切換 - 緊湊的設備性能、能耗限制 ## 函式執行時 - 需要良好的執行環境隔離 - 需要控制每次執行的資源使用 - 例如:AWS計費 ## 函數進行時 - 單進程服務無法隔離執行環境 - VM Context可隔離namespace,無法隔離rumtime操作(API) - WorkerThread無法細分單次資源使用(權限或CPU資源) ## Conclusion - lower CPU using time - 降低 runtime 冷啟動時間 - 能夠隔離運行環境 - 能夠控制運行資源 ## what happen as nodejs launch 1. initialize uv / vm / platform 2. code-cache / snapshot (after v10 -> built-in-module to code-cache (保存字節碼 in binary) -> decrease time consuming) 3. bootstrap loader / node / env (to loaded required dependencies and built-in modules) (消耗大部分時間) 4. main (app.js) / pre_execution 5. user scipts 6. libraries ## major consuming time - loader main/pre_execution (step3 and step4) ## 時間花在哪 - parse/compile (save by code-cache) - interpret (save by snapshot) - run ## Preloaded - 嵌入式系統庫 - 函數運行庫 ## Prior Arts 1. Zygote ## limitations 1. continuous seed runtime ## what's next 1. collect usage case 2. standardize fork APi
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up