Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Varnish 快取命中率深度分析:varnishstat 關鍵指標解讀與優化策略

編輯:Linux 教學

命中率為何無法達 100%

  • 快取空間有限:LRU 淘汰機制可能誤刪即將存取的熱點物件。
  • TTL 過期:短 TTL 導致周期性未命中。
  • 不可快取回應:含 Set-Cookie、Cache-Control: private/no-store、Vary:* 等標頭的回應預設不快取,且請求時也不查快取。

varnishstat 即時監控關鍵計數器


client_conn     9908723  94.05  Client connections accepted
client_req      16433490 155.99 Client requests received
cache_hit       8751732  83.07  Cache hits
cache_hitpass   42592    0.40   Cache hits for pass
cache_miss      7573389  71.89  Cache misses
backend_conn    3889845  36.92  Backend conn. success
backend_fail    4536     0.04   Backend conn. failures
n_lru_nuked     183957   —      LRU nuked objects
n_expired       6344546  —      Expired objects

核心指標解讀

計數器含義異常信號
cache_hit / client_req命中率< 80% 需檢查 TTL、快取大小、VCL 邏輯
cache_miss未命中需回源持續高 → 快取太小或 TTL 太短
n_lru_nukedLRU 強制淘汰次數持續增長 → 快取空間不足
n_expired自然過期物件數佔比高 → TTL 設定過短
backend_fail後端連線失敗> 0% → 後端不穩或健檢閾值過嚴
backend_busy後端連線池滿> 0 → 需擴充後端或調整連線池
sess_drop / n_wrk_drop連線/工作請求被丟棄非零 → 執行緒池或佇列不足

優化策略對應表

  • n_lru_nuked 高:增大 -s malloc, SIZE 或 -s file,... 快取空間。
  • n_expired 高:延長 TTL、在 VCL 中 set beresp.ttl = 1h; 覆寫後端短 TTL。
  • cache_miss 高且 n_lru_nuked 低:檢查 vcl_recv 是否正確 return (lookup)、vcl_backend_response 是否誤設 set beresp.uncacheable = true;。
  • backend_fail 高:調整 .probe 間隔/閾值、檢查後端健康狀態。
  • 不可快取流量大:在 vcl_backend_response 移除 Set-Cookie、正規化 Cache-Control、處理 Vary。

持續觀測建議

將 varnishstat -1 定期輸出至時序資料庫(Prometheus/InfluxDB),配合 Grafana 儀表板監控 Hit Rate、Miss Rate、LRU Nuked、Backend Health 四大核心曲線,設定告警閾值。

Copyright © Windows教程網 All Rights Reserved