![如何提高Varnish的吞吐量?](https://linux22.com/image/599298/%E5%A6%82%E4%BD%95%E6%8F%90%E9%AB%98Varnish%E7%9A%84%E5%90%9E%E5%90%90%E9%87%8F%EF%BC%9F.png)
有时在繁忙的 Pressflow 网站上,我注意到未经身份验证的用户会超时,而服务器的端口远未饱和,有大量未使用的内存并且服务器负载非常低。
此外,自从我迁移到新的 Varnish 服务器并采用新配置后,网站的带宽使用量下降了约 30%。因此,我怀疑下降可能是由于 Varnish 的错误配置造成的。
以下是一些相关参数:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-b localhost:8080 \
-u varnish -g varnish \
-S /etc/varnish/secret \
-p thread_pools=14 \
-p thread_pool_min=200 \
-p thread_pool_max=5000 \
-p listen_depth=128 \
-p thread_pool_add_delay=2\
-p lru_interval=20 \
-h classic,72227 \
-p session_linger=120 \
-p sess_workspace=32768 \
-p connect_timeout=600 \
-s malloc,15G"
# 这是 varnishstat 的最新输出:
1+21:07:54
Hitrate ratio: 10 13 13
Hitrate avg: 0.8405 0.8408 0.8408
21003013 158.92 129.32 Client connections accepted
35390015 283.85 217.91 Client requests received
4696051 26.99 28.92 Cache hits
79 0.00 0.00 Cache hits for pass
939223 4.00 5.78 Cache misses
10041628 89.95 61.83 Backend conn. success
108 0.00 0.00 Backend conn. failures
20651750 162.92 127.16 Backend conn. reuses
3202624 22.99 19.72 Backend conn. was closed
23854404 187.90 146.88 Backend conn. recycles
17397 0.00 0.11 Fetch head
20499527 189.90 126.22 Fetch with Length
6536900 37.98 40.25 Fetch chunked
2410249 15.99 14.84 Fetch wanted close
4 0.00 0.00 Fetch failed
2261 . . N struct sess_mem
1728 . . N struct sess
263703 . . N struct object
264848 . . N struct objectcore
138282 . . N struct objecthead
116 . . N struct vbe_conn
2800 . . N worker threads
2801 0.00 0.02 N worker threads created
2889 0.00 0.02 N worker threads limited
832 0.00 0.01 N overflowed work requests
1 . . N backends
658946 . . N expired objects
6948 . . N LRU nuked objects
3425448 . . N LRU moved objects
31922006 257.87 196.56 Objects sent with write
21002526 160.92 129.32 Total Sessions
35390015 283.85 217.91 Total Requests
750 0.00 0.00 Total pipe
29752808 252.87 183.20 Total pass
所以我的问题是:我怎么知道 Varnish 线程是否已经饱和?我应该如何操作参数来提高吞吐量?谢谢
答案1
我主要建议调整thread_pool_min和thread_pool_max,其他值没有太大帮助。-p thread_pools=2 \ -p thread_pool_min=500 \ -p thread_pool_max=5000 \
具体来说,将 thread_pools 设置为 CPU 数量根本没有帮助,可能会降低您的机器速度。这只是一个猜测,但也许这已经解决了您的问题!:)
您会在这里找到非常好的解释:http://book.varnish-software.com/4.0/chapters/Tuning.html