Varnish和ESI,性能如何?

net*_*ain 9 caching reverse-proxy varnish server-side-includes edge-side-includes

我想知道当前ESI模块的性能如何?我在网上看过一些关于清漆上的ESI性能实际上比实际情况慢的帖子.

说我有一个超过3500 esi包含的页面,这将如何表现?esi是为这种用途而设计的吗?

Nik*_*iko 17

我们使用Varnish和ESI将子文档嵌入到JSON文档中.基本上我们的app-server的响应如下:

[
  <esi:include src="/station/best_of_80s" />,
  <esi:include src="/station/herrmerktradio" />,
  <esi:include src="/station/bluesclub" />,
  <esi:include src="/station/jazzloft" />,
  <esi:include src="/station/jahfari" />,
  <esi:include src="/station/maximix" />,
  <esi:include src="/station/ondalatina" />,
  <esi:include src="/station/deepgroove" />,
  <esi:include src="/station/germanyfm" />,
  <esi:include src="/station/alternativeworld" />
]
Run Code Online (Sandbox Code Playgroud)

包含的资源是完整且有效的JSON响应.所有站点的完整列表大约是1070.因此,当缓存很冷并且第一个请求时,完整的站点列表会在我们的后端发出1000个请求.当缓存是热的时,ab看起来像这样:

$ ab -c 100 -n 1000 http://127.0.0.1/stations
[...]

Document Path:          /stations
Document Length:        2207910 bytes

Concurrency Level:      100
Time taken for tests:   10.075 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      2208412000 bytes
HTML transferred:       2207910000 bytes
Requests per second:    99.26 [#/sec] (mean)
Time per request:       1007.470 [ms] (mean)
Time per request:       10.075 [ms] (mean, across all concurrent requests)
Transfer rate:          214066.18 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   11   7.3      9      37
Processing:   466  971  97.4    951    1226
Waiting:        0   20  16.6     12      86
Total:        471  982  98.0    960    1230

Percentage of the requests served within a certain time (ms)
  50%    960
  66%    985
  75%    986
  80%    988
  90%   1141
  95%   1163
  98%   1221
  99%   1229
 100%   1230 (longest request)
$ 
Run Code Online (Sandbox Code Playgroud)

100 rec/sec看起来不太好,但考虑文档的大小.214066Kbytes/sec使1Gbit接口过饱和.

具有热缓存ab(ab -c 1 -n 1 ...)的单个请求显示83ms/req.

后端本身是基于redis的.我们在NewRelic中测量的平均响应时间为0.9ms [原文如此].重新启动Varnish后,带有冷缓存的第一个请求(ab -c 1 -n 1 ...)显示3158ms/rec.这意味着它需要Varnish,我们的后端每个ESI约3ms包括生成响应时.这是一款标准核心i7披萨盒,内置8芯.我在满负荷的情况下测量了这个.我们以这样的方式服务大约150mio req /月,命中率为0.9.这些数字确实表明ESI-includes是连续解决的.

在设计这样的系统时你必须考虑的是1)当缓存冷却时你的后端能够在Varnish重新启动后承担负载2)通常你的资源不会一次性到期.如果是我们的电台,它们每隔一小时就会过期,但我们会在到期标头中添加最多120秒的随机值.

希望有所帮助.