Странное поведение nginx при кешировании

Volkov Oleg nginx at teratelecom.ru
Fri Jun 5 00:25:26 MSD 2009


В Чтв, 04/06/2009 в 11:02 +0400, nginx пишет:
> В Срд, 03/06/2009 в 16:57 +0400, nginx пишет:
> > Наблюдается следующая картина
> > Включаю кеширование, прописав 
> > 
> >         proxy_read_timeout 65;
> > 	proxy_send_timeout 11;
> > 	proxy_connect_timeout 10;
> > 	proxy_next_upstream off;
> > 	proxy_ignore_headers Cache-Control;
> > 	proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2
> > keys_zone=zone1:10m;
> > 	proxy_cache zone1;
> > 	proxy_cache_key $server_name$uri?$memcached_args;
> > 	proxy_cache_min_uses 1;
> > 	proxy_cache_valid 10m;
> > 	proxy_cache_use_stale http_503;
> > 
> > У страницы 
> > Last-Modified
> > Wed, 03 Jun 2009 12:43:07 GMT
> > Expires
> > Wed, 03 Jun 2009 12:48:07 GMT
> > отличаются на 5 минут
> > 
> > Работает это все так. При перезапуске nginx подбирает из кеша страницу и 5 минут апачи не трогает,
> > через 5 минут начинает часть хапросов отдавать на апачи, причем логику проследить не удается. 
> > В чем может быть проблема?
> > Могу предоставить логи и полный конфиг, но не думаю что стоит это делать прямо сюда.
> 
> Привожу конфиги (закоментаренные строчки я пробовал раскрывать)
> 
> user nginx nginx;
> worker_processes 8;
> 
> error_log /var/log/nginx/error_log error;
> 
> worker_rlimit_nofile	8192;
> 
> events {
> 	worker_connections  8192;
> 	use epoll;
> }
> 
> http {
> 	server_names_hash_bucket_size   64;
> 	include		/etc/nginx/mime.types;
> 	default_type	application/octet-stream;
> 
> 	client_header_timeout 21;
> 	client_body_timeout 22;
> 	send_timeout 23;
> 	client_max_body_size 10m;
> 
> 	connection_pool_size 256;
> 	client_header_buffer_size 1k;
> 	large_client_header_buffers 4 2k;
> 	request_pool_size 4k;
> 
> 	gzip on;
> 	gzip_min_length	1100;
> 	gzip_buffers	16 8k;
> 	gzip_types	text/plain application/xml application/x-javascript;
> 
> 	output_buffers	8 32k;
> 	postpone_output	1460;
> 
> 	sendfile	on;
> 	tcp_nopush	on;
> 	tcp_nodelay	on;
> 
> 	keepalive_timeout 75 20;
> 	ignore_invalid_headers	on;
> 	index index.html;
>         proxy_read_timeout 65;
> 	proxy_send_timeout 11;
> 	proxy_connect_timeout 10;
> 	proxy_next_upstream off;
>         proxy_ignore_headers Cache-Control;
> 	perl_set $memcached_args 'sub {
> my $r=shift;
> $_=$r->args;
> if($_ ne "")
> {
>     s/(&|^)[upd]id=[^&]*//igo;
>     s/^&//io;
> }
> return $_;
> 	}';
> 	proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2
> keys_zone=zone1:10m;
> 	proxy_cache_path /var/tmp/nginx/proxy_cache2 levels=1:2
> keys_zone=zone2:10m;
> 	proxy_cache_key $server_name$uri?$memcached_args;
> #	proxy_cache_min_uses 1;
> #	proxy_cache_valid any 10m;
> #	proxy_cache_use_stale http_503;
> #	proxy_ignore_client_abort on;
> 
>         log_format  site_log_format  '$msec $request_time $remote_addr '
> '$status $body_bytes_sent $gzip_ratio $server_name$request_uri
> $http_referer';
>         log_format  stat_log_format  '$msec $request_time $remote_addr '
> '$status $uid_got $uid_set $server_name$request_uri $http_referer '
> '$upstream_addr $upstream_response_time $upstream_status $time_local
> "$http_user_agent" '
> '$request_length $body_bytes_sent $gzip_ratio $request_body_file';
> 	access_log /nginx_log/all_log site_log_format;
> 
> 	client_body_in_file_only on;
> 	client_body_temp_path /nginx_post 3 3;
> 	    
>         limit_zone too $server_name 1m;
>     
> 	userid          on;
> 	userid_name     stat_uid;
> 	userid_domain   none;
> 	userid_path     /;
> 
> 	open_file_cache          max=1000  inactive=20s;
> 	open_file_cache_valid    30s;
> 	open_file_cache_min_uses 2;
> 	open_file_cache_errors   on;
> 
> 	include /etc/nginx/include/*;
> }
> 
> Конфиг для данного вирт. хоста
> 
> server {
>     listen	95.129.248.90;
>     server_name	... ;
>     charset	utf-8;
>     access_log 	/nginx_log/..._log site_log_format;
> 
>     location ~* ^(.+\.(php|php3|html)|.*/)$ {
> 	limit_conn	too 5;
> 	error_page      503 /503.html;
>         proxy_cache zone2;
>         proxy_pass http://backend2;
>         proxy_set_header  Host ...;
>         proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
>         proxy_set_header X-Real-IP  $remote_addr;
>         index        index.php index.html;
>         access_log   /nginx_log/stat_log stat_log_format;
> 	access_log   /nginx_log/..._log site_log_format;
>     }
>     location /503.html {
> 	internal;
> 	root			/data/test/htdocs;
> 	charset 		windows-1251;
>         access_log 		/nginx_log/stat_log stat_log_format;
>     }
>     location ~ / {
>         root   ...;
>     }
> }
> upstream backend2 {
>     ip_hash;
>     server IP1 max_fails=3 fail_timeout=60s ;
>     server IP2 max_fails=3 fail_timeout=60s ;
> }
> 
> кусок лога
> 
> 1244098296.622 0.000 78.24.24.241 200 - - 04/Jun/2009:10:51:36
> 1244098297.318 0.000 95.129.248.46 200 - - 04/Jun/2009:10:51:37
> 1244098297.418 0.000 212.87.187.3 200 - - 04/Jun/2009:10:51:37
> 1244098298.425 0.000 85.249.160.42 200 - - 04/Jun/2009:10:51:38
> 1244098298.668 0.000 62.192.233.99 200 - - 04/Jun/2009:10:51:38
> 1244098299.040 0.000 84.50.208.4 200 - - 04/Jun/2009:10:51:39
> 1244098299.650 0.000 92.112.145.87 200 - - 04/Jun/2009:10:51:39
> 1244098299.745 0.000 193.110.112.100 200 - - 04/Jun/2009:10:51:39
> 1244098300.025 0.000 89.113.208.212 200 - - 04/Jun/2009:10:51:40
> 1244098300.068 0.000 77.245.197.224 200 - - 04/Jun/2009:10:51:40
> 1244098301.812 0.000 95.72.148.100 200 - - 04/Jun/2009:10:51:41
> 1244098302.674 0.000 88.200.188.123 200 - - 04/Jun/2009:10:51:42
> 1244098303.434 0.095 78.36.7.112 200 0.095 200 04/Jun/2009:10:51:43
> 1244098303.888 0.089 95.52.186.111 200 0.089 200 04/Jun/2009:10:51:43
> 1244098304.902 0.000 193.200.38.246 200 - - 04/Jun/2009:10:51:44
> 1244098305.007 0.000 84.204.156.166 200 - - 04/Jun/2009:10:51:45
> 1244098305.044 0.000 89.169.135.77 200 - - 04/Jun/2009:10:51:45
> 1244098306.220 0.000 94.248.0.51 200 - - 04/Jun/2009:10:51:46
> 1244098306.979 0.093 93.170.0.46 200 0.093 200 04/Jun/2009:10:51:46
> 1244098307.026 0.000 87.117.35.27 200 - - 04/Jun/2009:10:51:47
> 1244098307.197 0.000 93.185.176.158 200 - - 04/Jun/2009:10:51:47
> 1244098307.885 0.091 78.37.56.216 200 0.091 200 04/Jun/2009:10:51:47
> 1244098308.458 0.000 85.202.126.3 200 - - 04/Jun/2009:10:51:48
> 1244098309.622 0.000 94.180.3.134 200 - - 04/Jun/2009:10:51:49
> 1244098310.002 0.000 93.124.97.77 200 - - 04/Jun/2009:10:51:50
> 1244098310.601 0.000 80.85.185.144 200 - - 04/Jun/2009:10:51:50
> 1244098311.196 0.000 92.243.167.96 200 - - 04/Jun/2009:10:51:51
> 1244098311.254 0.000 85.174.96.206 200 - - 04/Jun/2009:10:51:51
> 1244098311.752 0.000 91.192.20.10 200 - - 04/Jun/2009:10:51:51
> 1244098311.981 0.000 81.200.149.4 200 - - 04/Jun/2009:10:51:51
> 1244098312.006 0.000 195.206.43.10 200 - - 04/Jun/2009:10:51:52
> 1244098312.507 0.000 80.58.205.45 200 - - 04/Jun/2009:10:51:52
> 1244098312.569 0.000 94.51.233.120 200 - - 04/Jun/2009:10:51:52
> 1244098313.140 0.000 92.53.92.81 200 - - 04/Jun/2009:10:51:53
> 1244098313.270 0.000 80.70.236.45 200 - - 04/Jun/2009:10:51:53
> 1244098313.486 0.000 91.200.55.28 200 - - 04/Jun/2009:10:51:53
> 1244098314.004 0.000 79.120.0.168 200 - - 04/Jun/2009:10:51:54
> 1244098314.097 0.000 77.232.15.242 200 - - 04/Jun/2009:10:51:54
> 1244098314.536 0.000 95.220.9.101 200 - - 04/Jun/2009:10:51:54
> 1244098314.856 0.000 89.169.77.22 200 - - 04/Jun/2009:10:51:54
> 1244098317.472 0.000 194.44.238.38 200 - - 04/Jun/2009:10:51:57
> 1244098318.030 0.000 95.165.12.16 200 - - 04/Jun/2009:10:51:58
> 1244098318.042 0.099 91.192.60.34 200 0.099 200 04/Jun/2009:10:51:58
> 1244098318.174 0.000 217.8.87.211 200 - - 04/Jun/2009:10:51:58
> 1244098318.962 0.000 92.101.106.188 200 - - 04/Jun/2009:10:51:58
> 1244098319.475 0.000 95.78.128.37 200 - - 04/Jun/2009:10:51:59
> 1244098320.192 0.086 95.129.248.46 200 0.086 200 04/Jun/2009:10:52:00
> 1244098320.614 0.000 81.9.56.61 200 - - 04/Jun/2009:10:52:00
> 1244098321.667 0.000 88.205.252.233 200 - - 04/Jun/2009:10:52:01
> 1244098321.913 0.000 95.161.253.133 200 - - 04/Jun/2009:10:52:01
> 1244098322.635 0.000 93.185.185.8 200 - - 04/Jun/2009:10:52:02
> 1244098322.904 0.000 188.17.28.127 200 - - 04/Jun/2009:10:52:02
> 1244098323.454 0.000 95.72.120.214 200 - - 04/Jun/2009:10:52:03
> 1244098323.604 0.000 79.124.109.5 200 - - 04/Jun/2009:10:52:03
> 
> Где нет двух минусов - запросы на бэкенд
> 
> В кеше лежит файлик, заголовки которого 
> HTTP/1.1 200 OK
> Date: Thu, 04 Jun 2009 06:59:37 GMT
> Server: Apache
> X-Powered-By: PHP/5.2.8-pl2-gentoo
> Last-Modified: Thu, 04 Jun 2009 06:59:37 GMT
> Expires: Thu, 04 Jun 2009 07:04:37 GMT
> Connection: close
> Content-Type: text/html; charset=UTF-8
> 
> Есть идеи?

Добавления.
Если я делаю количество воркеров 1, то поведение меняется
При истечении времени кеширования страницы, которая лежит в кеше на
момент запуска nginx происходит или замена страницы:

...
1244145883.888 0.000 95.129.248.46 200 - -
1244145884.641 0.000 92.100.135.45 200 - -
1244145884.946 0.000 83.167.100.72 200 - -
1244145887.161 0.092 93.157.184.210 200 0.092 200
1244145887.281 0.000 79.120.45.135 200 - -
1244145887.307 0.000 78.36.249.37 200 - -
1244145887.757 0.000 90.151.27.189 200 - -
1244145887.779 0.000 94.248.3.140 200 - -
...

 или ломается насовсем

...
1244145734.353 0.000 94.179.248.164 200 - -
1244145735.152 0.000 77.232.15.223 200 - -
1244145736.682 0.000 95.71.0.238 200 - -
1244145737.181 0.000 95.134.99.150 200 - -
1244145738.217 0.000 87.249.56.212 200 - -
1244145738.783 0.000 188.134.6.111 200 - -
1244145739.065 0.000 85.175.120.10 200 - -
1244145740.206 0.037 89.113.170.82 200 0.037 200
1244145740.376 0.039 62.140.253.6 200 0.035 200
1244145740.430 0.037 62.140.244.28 200 0.037 200
1244145740.577 0.034 89.207.99.217 200 0.034 200
1244145740.616 0.035 77.239.239.143 200 0.035 200
1244145740.747 0.038 92.113.121.159 200 0.038 200
1244145740.831 0.035 95.129.248.45 200 0.035 200
...
и не чинится уже никогда, до перезапуска nginx

Причем если конкрентный урл в нгинкс не "сломался" за первый цикл, то
дальше можно ждать уже долго, не "ломается".

Очистка кэша перед перезапуском nginx не помогает.

Версия nginx 0.7.59 под 32 linux.


Как-то не верится, что данная проблема только у меня.

-- 
С уважением,
Волков Олег







More information about the nginx-ru mailing list