我对这个 nginx 配置运行测试:
server {
listen 80;
#error_log /var/log/debug.log debug;
server_name test1.ostrovok.ru;
location / {
fastcgi_pass 127.0.0.1:12345;
client_max_body_size 20000k;
charset utf8;
}
location /photos {
proxy_pass http://imageserver;
proxy_store /srv/trololo/$request_uri;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /srv/trololo/temp;
access_log off;
}
}
# Backend image server
server {
listen 12346;
server_name localhost;
location / {
root /srv/trololo;
sendfile off;
aio on;
output_buffers 200 10000k;
gzip off;
directio 512;
access_log off;
expires max;
}
}
# Upstream
upstream imageserver {
server localhost:12346;
}
测试:
siege -c 100 -r 5 -f urls.txt -t 120s --internet
结果
Transactions: 12352 hits
Availability: 100.00 %
Elapsed time: 120.00 secs
Data transferred: 1591.91 MB
Response time: 0.46 secs
Transaction rate: 102.93 trans/sec
Throughput: 13.27 MB/sec
Concurrency: 47.13
Successful transactions: 12352
Failed transactions: 0
Longest transaction: 15.08
Shortest transaction: 0.05
为什么最长交易和最短交易之间有这样的差异?
测试的前 7 秒 - 良好:
HTTP/1.1 200 0.05 secs: 113575 bytes ==> /photos/resize/600/900/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 16135 bytes ==> /photos/resize/900/100/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 132249 bytes ==> /photos/resize/500/700/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 8513 bytes ==> /photos/resize/100/300/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 8513 bytes ==> /photos/resize/100/600/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 113575 bytes ==> /photos/resize/600/900/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 75669 bytes ==> /photos/resize/500/900/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 113575 bytes ==> /photos/resize/600/1100/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 29708 bytes ==> /photos/resize/300/500/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 161191 bytes ==> /photos/resize/700/300/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 200775 bytes ==> /photos/resize/800/700/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 29708 bytes ==> /photos/resize/300/200/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 29708 bytes ==> /photos/resize/300/1000/20110901/0300/22.png
但是之后:
HTTP/1.1 200 5.06 secs: 52441 bytes ==> /photos/resize/400/1100/20110901/0300/22.png
HTTP/1.1 200 5.06 secs: 235335 bytes ==> /photos/resize/700/900/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 5.07 secs: 305657 bytes ==> /photos/resize/1000/500/20110901/0300/22.png
HTTP/1.1 200 5.07 secs: 252759 bytes ==> /photos/resize/900/1000/20110901/0300/22.png
HTTP/1.1 200 5.07 secs: 200775 bytes ==> /photos/resize/800/700/20110901/0300/22.png
HTTP/1.1 200 5.06 secs: 77258 bytes ==> /photos/resize/400/800/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 376880 bytes ==> /photos/resize/1100/700/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 16135 bytes ==> /photos/resize/900/100/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 161191 bytes ==> /photos/resize/700/800/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 16135 bytes ==> /photos/resize/700/100/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 5.06 secs: 44446 bytes ==> /photos/resize/400/200/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 343273 bytes ==> /photos/resize/900/800/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 518488 bytes ==> /photos/resize/1100/800/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 251162 bytes ==> /photos/resize/1100/300/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 161191 bytes ==> /photos/resize/700/900/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 16135 bytes ==> /photos/resize/300/100/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 8513 bytes ==> /photos/resize/100/600/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 3242 bytes ==> /photos/resize/100/300/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 29708 bytes ==> /photos/resize/600/100/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 24521 bytes ==> /photos/resize/200/1000/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 29708 bytes ==> /photos/resize/300/900/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 166648 bytes ==> /photos/resize/600/400/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 52441 bytes ==> /photos/resize/400/500/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 113652 bytes ==> /photos/resize/1000/400/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 233737 bytes ==> /photos/resize/800/600/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 113575 bytes ==> /photos/resize/600/500/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 53067 bytes ==> /photos/resize/300/1100/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 12417 bytes ==> /photos/resize/200/1100/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 99703 bytes ==> /photos/resize/800/300/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 252759 bytes ==> /photos/resize/900/700/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 8513 bytes ==> /photos/resize/100/1000/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 3242 bytes ==> /photos/resize/100/1000/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 52441 bytes ==> /photos/resize/400/1100/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 99703 bytes ==> /photos/resize/800/300/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 376880 bytes ==> /photos/resize/1100/500/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 161191 bytes ==> /photos/resize/700/1100/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 24521 bytes ==> /photos/resize/200/1000/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 251162 bytes ==> /photos/resize/1100/300/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 305657 bytes ==> /photos/resize/1000/500/20110901/0300/22.png
HTTP/1.1 200 0.06 secs: 518488 bytes ==> /photos/resize/1100/900/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.08 secs: 113575 bytes ==> /photos/resize/600/1000/20110901/0300/22.png
HTTP/1.1 200 5.06 secs: 166648 bytes ==> /photos/resize/600/700/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.06 secs: 235335 bytes ==> /photos/resize/700/800/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 235335 bytes ==> /photos/resize/700/700/20110831/2048/Ekafisha-Firefox.png
HTTP/1.1 200 0.05 secs: 12417 bytes ==> /photos/resize/200/700/20110901/0300/22.png
HTTP/1.1 200 0.05 secs: 16135 bytes ==> /photos/resize/1100/100/20110831/2048/Ekafisha-Firefox.png
[完整测试日志文件1
等等
为什么?
答案1
将对 /photos 的静态请求代理到同一 localhost 上的同一 nginx 的目的是什么?如果您确实需要它,最好不要在代理时将内容存储到磁盘,您的代理应设置为完全透明模式(您应该设置proxy_buffering
为off
)。否则,您的设置中就会有无用的磁盘活动 - nginx 会在代理端为您的 /photos 位置创建临时文件。这可能是某些请求性能下降的根本原因。