A good day to trie-hard: saving compute 1% at a time
Link📌 Summary: 本文探討了Cloudflare團隊如何透過優化請求處理功能來減少CPU使用率,著重於其新的开源Rust库——trie-hard。隨著請求量的劇增,團隊發現每個請求需執行的clear_internal_headers函數佔用著1.7%的CPU時間,因此進行了優化工作。通過將清除內部標頭的邏輯改進和選擇更高效的資料結構,最終將平均執行時間從3.65微秒減少到0.93微秒,使CPU使用率優化至1.28%。優化過程中使用了基準測試工具,並在實際生產中進行了性能監測,結果驗證了其預測的效能。🎯 Key Points:
- Cloudflare的Pingora框架支撐著全球高達3500萬個請求每秒。
- 原始的可執行function clear_internal_headers使用過多CPU時間,佔總使用率的1.7%。
- 透過調整資料結構和清除邏輯,優化後的函數執行時間顯著縮短。
- 使用trie資料結構的新的實現trie-hard,讓執行時間小於1微秒。
- 性能測試結果與實際運行數據一致,確保了優化的有效性。
🔖 Keywords: #Cloudflare #Rust #優化 #性能測試 #開源
A good day to trie-hard: saving compute 1% at a time
Pingora handles 35M+ requests per second, so saving a few microseconds per request can translate to thousands of dollars saved on computing costs. In this post, we share how we freed up over 500 CPU cores by optimizing one function and announce trie-hard, the open source crate that we created to do it.