Ошибка 502, linux 2.6, в бэкэнде апач 1.3 через tcp-сокеты

alexus alexus at fenek.ru
Tue Jan 30 08:10:08 MSK 2007


Здравствуйте.

Последнее время (с ростом нагрузки) в логе появляются следующие строчки, а клиенты получают 502 Bad Gateway.
2007/01/30 06:01:03 [error] 16336#0: *3706761 upstream prematurely closed connection while reading response header from upstream, client: 66.249.65.238, server: www.coolsite.net, URL: "/top10/?curPos=90", upstream: "http://127.0.0.1:81/top10/?curPos=90", host: "www.coolsite.net"
2007/01/30 06:13:40 [error] 16337#0: *3714929 upstream prematurely closed connection while reading response header from upstream, client: 74.6.86.136, server: www.siteplanet.ru, URL: "/price/?curPos=0", upstream: "http://127.0.0.1:81/price/?curPos=0", host: "www.siteplanet.ru"
2007/01/30 06:15:10 [error] 16337#0: *3716150 upstream prematurely closed connection while reading response header from upstream, client: 66.249.65.238, server: www.coolsite.net, URL: "/top10/?cat=21", upstream: "http://127.0.0.1:81/top10/?cat=21", host: "www.coolsite.net"
2007/01/30 06:19:55 [error] 16338#0: *3720430 upstream prematurely closed connection while reading response header from upstream, client: 62.165.59.30, server: www.siteplanet.ru, URL: "/price/", upstream: "http://127.0.0.1:81/price/", host: "www.siteplanet.ru", referrer: "http://kia.siteplanet.ru/index/index_7.html?template=33"

Закономерность замечена одна - при бОльшей загрузке больше вероятность
получить 502 (начинается при LA > 1.5)
Это происходит со всеми сайтами, как с легкими, так и тяжелыми.
В логе апача все чисто.
linux 2.6.16 (Gentoo), nginx 0.4.14, (установлен из Portage, пробовал
разные версии), apache 1.3.37, php 4.4.4, mysql 5.0.26-r2.
Апач запускается в количестве 10 рабочих процессов, и, судя по
server-status, обрабатывает около миллиона запросов в сутки.
Железка P4 2.8 (HT), 1 Gb RAM. Всего tcp соединений (в том числе локльных и
TIME_WAIT) в любой момент времени меньше 1000.
# netstat -an | grep tcp | wc -l
657

Искал по архиву рассылки, но ничего подходящего не нашел.
Подскажите, что подкрутить. Возможно, в моем конфиге есть какая-то
глупая ошибка.
Заранее спасибо.

== Вывод top

top - 07:58:38 up 4 days, 22:48,  1 user,  load average: 6.46, 8.29, 10.08
Tasks: 122 total,  14 running, 108 sleeping,   0 stopped,   0 zombie
Cpu(s): 84.2% us, 14.7% sy,  0.0% ni,  0.2% id,  0.0% wa,  0.0% hi,  1.0% si
Mem:    906252k total,   833412k used,    72840k free,    19848k buffers
Swap:  2000084k total,      120k used,  1999964k free,   308116k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2142 apache    16   0 60304  37m  19m R   20  4.2  32:46.13 apache
 2151 apache    15   0 60432  37m  19m S   19  4.3  33:37.05 apache
 2153 apache    15   0 62152  40m  20m S   17  4.6  33:07.48 apache
 2154 apache    16   0 60400  39m  21m R   13  4.4  33:12.41 apache
 2143 apache    16   0 61192  39m  20m S   10  4.4  33:25.99 apache
 2150 apache    15   0 61476  40m  21m S   10  4.6  33:13.11 apache
 2149 apache    15   0 60384  38m  20m R    9  4.3  32:58.50 apache
 2145 apache    15   0 60564  40m  21m R    9  4.5  33:16.77 apache
 2152 apache    15   0 60300  39m  21m S    8  4.5  33:05.60 apache
14652 root      25   0  201m 195m 1440 R    8 22.1  16:31.66 7z
 2148 apache    16   0 60192  38m  20m R    8  4.4  33:13.09 apache
16338 apache    15   0 11324 8644  848 S    1  1.0   0:32.07 nginx
14621 root      15   0  8804 4300 1432 S    1  0.5   0:59.85 mysqldump
30206 mysql     16   0  121m  56m 5192 S    1  6.4   0:00.03 mysqld
29391 postgres  17   0 21816 4928 4128 R    1  0.5   0:00.03 postmaster
30200 mysql     16   0  121m  56m 5192 R    1  6.4   0:00.02 mysqld
30201 mysql     16   0  121m  56m 5192 S    1  6.4   0:00.02 mysqld
14630 mysql     16   0  121m  56m 5192 S    0  6.4   0:21.22 mysqld


== Конфиг nginx

user  apache apache;

worker_processes  3;

error_log /var/log/nginx/error_log info;

events {
        worker_connections  1024;
        use epoll;
}

http {
        include         /etc/nginx/mime.types;
        default_type    application/octet-stream;
        server_names_hash_max_size 2048;
        server_names_hash_bucket_size 128;

        log_format main
                '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" '
                '"$gzip_ratio" "$host"';

        client_header_timeout   10m;
        client_body_timeout     10m;
        send_timeout            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    4 8k;
        gzip_types      text/plain;

        output_buffers  8 1024k;
        postpone_output 1460;

        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     on;

        keepalive_timeout       75 20;

        ignore_invalid_headers  on;

        index index.html index.shtml;
        
        proxy_connect_timeout      120;
        proxy_send_timeout         30;
        proxy_read_timeout         30;
        proxy_buffering             on;
        proxy_buffer_size          32k;
        proxy_buffers              12 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;

        server {
                listen 80;
                server_name example.ru www.example.ru;
                access_log /var/log/nginx/example main;
                proxy_redirect http://example.ru:81/ http://example.ru/;
                location / {
                        proxy_set_header Host 'example.domain.net';
                        proxy_pass      http://localhost:81;
                }
                location ~* ^.+\.(jpg|css|js|gif|html|htm|tif|doc|ico|avi|mp3|txt)$ {
                        root         /home/example/www/;
                        access_log   off;
                }
       }

        server {
                listen 80;
                server_name cool.site.ru coolsite.net www.coolsite.net coolsite.ru www.coolsite.ru;
                access_log /var/log/nginx/coolsite main;
                location / {
                        proxy_set_header Host 'cool.site.ru';
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_pass      http://localhost:81;
                }
                location ~* ^.+\.(jpg|jpeg|gif|txt|ico|css|js|doc)$ {
                        root /home/coolsite/www;
                        access_log /var/log/nginx/coolsite_static main;
                        expires 30d;
                }
        }
}

итд.. виртхостов несколько сотен, доменов несколько тысяч.

-- 
С уважением,
 Alexus                          mailto:alexus at fenek.ru






More information about the nginx-ru mailing list