歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

深入探討Varnish緩存命中率

也許你還在為剛才動態內容獲得7336.76 reqs/s的吞吐率感到振奮,等等,理想和現實是有差距的,你要忍受現實的殘酷,別忘了,我們壓力測試中的動態內容都處於全緩存情況下,也就是每次請求都命中緩存,這在現實中往往是不可能的。
首先,緩存區空間大小是有限的,而我們的站點可能有大量的內容需要被緩存,而不像前邊壓力測試時只有一個內容。一旦緩存區被裝滿,那麼緩存管理器便會淘汰一些它認為不再需要的緩存內容,比如通過LRU(最近最少使用算法)將使用頻率較低的緩存內容淘汰出去,但是,這裡判斷“不常使用”的標准是不嚴格的,也許被淘汰的內容就是你將要訪問的下一個內容,這便影響了它的命中率。
其次,緩存的過期時間也影響到它的命中率,假如有效期很短,為10秒,那麼最少10秒便會有一次無法命中。
還有,有些內容可能根本沒有被代理服務器緩存,比如這些內容包含了set-cookie等不可緩存的HTTP頭信息,導致反向代理不會緩存它們,並且在浏覽器請求它們的時候也不會去緩存區查找。這是影響命中率的一個重要因素,但往往被我們所忽略。
幸運的是,這些問題我們都可以輕松的解決,前提是,我們需要了解反向代理緩存的實時工作狀態,比如Varnish便提供了一個命令行的狀態監控程序varnishstat,我們打開它,便看到了當前時刻的狀態,如下:


client_conn 9908723 94.05 Client connections accepted
client_drop 0 0.00 Connection dropped, no sess/wrk
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_unhealthy 220 0.00 Backend conn. not attempted
backend_busy 0 0.00 Backend conn. too many
backend_fail 4536 0.04 Backend conn. failures
backend_reuse 3780212 35.88 Backend conn. reuses
backend_toolate 3866687 36.70 Backend conn. was closed
backend_recycle 7646677 72.58 Backend conn. recycles
backend_unused 0 0.00 Backend conn. unused
fetch_head 57 0.00 Fetch head
fetch_length 155097 1.47 Fetch with Length
fetch_chunked 7508522 71.27 Fetch chunked
fetch_eof 0 0.00 Fetch EOF
fetch_bad 0 0.00 Fetch had bad headers
fetch_close 3982 0.04 Fetch wanted close
fetch_oldhttp 0 0.00 Fetch pre HTTP/1.1 closed
fetch_zero 0 0.00 Fetch zero len
fetch_failed 0 0.00 Fetch failed
n_sess_mem 1033 . N struct sess_mem
n_sess 633 . N struct sess
n_object 1016443 . N struct object
n_vampireobject 0 . N unresurrected objects
n_objectcore 1017564 . N struct objectcore
n_objecthead 982903 . N struct objecthead
n_smf 2647421 . N struct smf
n_smf_frag 622470 . N small free smf
n_smf_large 3 . N large free smf
n_vbe_conn 12 . N struct vbe_conn
n_wrk 8000 . N worker threads
n_wrk_create 8000 0.08 N worker threads created
n_wrk_failed 0 0.00 N worker threads not created
n_wrk_max 11021 0.10 N worker threads limited
n_wrk_queue 0 0.00 N queued work requests
n_wrk_overflow 2441 0.02 N overflowed work requests
n_wrk_drop 0 0.00 N dropped work requests
n_backend 4 . N backends
n_expired 6344546 . N expired objects
n_lru_nuked 183957 . N LRU nuked objects
n_lru_saved 0 . N LRU saved objects
n_lru_moved 3692170 . N LRU moved objects
n_deathrow 0 . N objects on deathrow
losthdr 84 0.00 HTTP header overflows
n_objsendfile 0 0.00 Objects sent with sendfile
n_objwrite 15466812 146.81 Objects sent with write
n_objoverflow 0 0.00 Objects overflowing workspace
s_sess 9906155 94.03 Total Sessions
s_req 16433490 155.99 Total Requests
s_pipe 37 0.00 Total pipe
s_pass 108252 1.03 Total pass
s_fetch 7667658 72.78 Total fetch
s_hdrbytes 7187255662 68221.35 Total header bytes
s_bodybytes 111592032839 1059230.32 Total body bytes
sess_closed 1905544 18.09 Session Closed
sess_pipeline 0 0.00 Session Pipeline
sess_readahead 0 0.00 Session Read Ahead
sess_linger 15277717 145.02 Session Linger
sess_herd 13547370 128.59 Session herd
shm_records 1028855796 9765.89 SHM records
shm_writes 77957008 739.97 SHM writes
shm_flushes 131005 1.24 SHM flushes due to overflow
shm_cont 144281 1.37 SHM MTX contention
shm_cycles 427 0.00 SHM cycles through buffer
sm_nreq 15306717 145.29 allocator requests
sm_nobj 2024948 . outstanding allocations
sm_balloc 13595295744 . bytes allocated
sm_bfree 40091795456 . bytes free
sma_nreq 0 0.00 SMA allocator requests
sma_nobj 0 . SMA outstanding allocations
sma_nbytes 0 . SMA outstanding bytes
sma_balloc 0 . SMA bytes allocated
sma_bfree 0 . SMA bytes free
sms_nreq 14062 0.13 SMS allocator requests
sms_nobj 0 . SMS outstanding allocations
sms_nbytes 487 . SMS outstanding bytes
sms_balloc 6844837 . SMS bytes allocated
sms_bfree 6846298 . SMS bytes freed
backend_req 7668789 72.79 Backend requests made
n_vcl 1 0.00 N vcl total
n_vcl_avail 1 0.00 N vcl available
n_vcl_discard 0 0.00 N vcl discarded

Copyright © Linux教程網 All Rights Reserved