FreeBSD + nginx + php-fpm - задержка отдачи контента 1.2-1.7 сек

Tiberiy nginx-forum на nginx.us
Чт Ноя 17 10:16:57 UTC 2011


Привет, Алл.

Взываю за помощью к вселенскому
разуму.

Имеется высоконагруженная система 5
фронтов nginx (Round-Robin) и 20 бэков nginx+php-fpm (в
среднем 70-100 млн запросов  в сутки).
Тюнинг ОС произведен, настройки nginx
тоже старался сделать оптимальными.
Проблема возникает как на входе
кластера так и при обращении напрямую
на бэкэнд.
Проблема не зависит от логики php 
срипта.
Суть проблемы:
Создаем простой файл пхп с одной
строкой echo и оберткой в микротайм.
Скорость обработки срипта php-fpm 0.002 сек.
Скорость отдачи контента 1.2-1.7 сек. От
нагрузки данная величина только
увеличивается.

Помогите...

OS: FreeBSD 8.2

named запущен как кеширующий сервер с
параметром '-n 2' в resolv.conf первой строкой
идет nameserver 127.0.0.1
Для PHP 5.3.8 стоит акселератор APC.

Ядро: amd64 GENERIC + включен POLLING и мелкая
оптимизация:
maxusers 512
options DEVICE_POLLING
options HZ=1000
options  NBUF=2048
options  MAXDSIZ=(512*1024*1024)
options  DFLDSIZ=(128*1024*1024)
options  SOFTUPDATES


Файлы:
loader.conf:
ahci_load="YES"
aio_load="YES"
geom_mirror_load="yes"
geom_stripe_load="yes"
geom_cache_load="yes"
geom_label_load="yes"
accf_http_load="yes"
accf_data_load="yes"
accf_dns_load="yes"
coretemp_load="yes"
if_em_load="yes"
verbose_loading="yes"
boot_verbose="yes"
net.inet.ip.fw.default_to_accept=1

vm.kmem_size=4G

kern.maxfiles=204800
kern.maxfilesperproc=200000
kern.ipc.maxsockets=204800
kern.ipc.nmbclusters=204800
kern.ipc.nmbjumbop=192000
kern.ipc.somaxconn=8192
kern.ipc.shmmax=2147483648
kern.ipc.maxsockbuf=10485760
kern.ipc.nsfbufs=10240
kern.maxvnodes=200000
kern.ps_arg_cache_limit=4096

vm.pmap.shpgperproc=2048
vm.pmap.pg_ps_enabled=1

hw.bge.allow_asf=1

loader_logo="beastie"

net.inet.tcp.syncache.hashsize=1024
net.inet.tcp.syncache.bucketlimit=100
net.inet.tcp.tcbhashsize=32768
net.inet.tcp.syncache.cachelimit=65536
net.inet.tcp.hostcache.cachelimit=1966080

sysctl.conf
net.inet.tcp.delayed_ack=0
net.inet.tcp.msl=30000
net.inet.tcp.fast_finwait2_recycle=1
net.inet.ip.intr_queue_maxlen=4096
net.inet.tcp.blackhole=2
net.inet.udp.blackhole=1
net.inet.tcp.recvspace=8192
net.inet.tcp.recvbuf_auto=0
net.inet.icmp.icmplim=100
net.inet.tcp.sendspace=16384
net.inet.tcp.sendbuf_auto=1
net.inet.tcp.sendbuf_inc=8192
net.inet.tcp.sendbuf_max=131072
net.inet.tcp.maxtcptw=102400
net.inet.tcp.nolocaltimewait=1
net.inet.tcp.syncookies=1
net.isr.direct=0
kern.polling.enable=1
net.inet.tcp.rfc3465=0

nginx.conf:
user  www;
worker_processes 4;
worker_rlimit_nofile 200000;
worker_priority -1;
timer_resolution 100ms;


pid             /var/run/nginx.pid;
error_log       /var/log/nginx-error.log error;

events {
    worker_connections  50000;
    use kqueue;
}


http {
    log_format upstream   '$upstream_addr | $request $status
"$http_user_agent" [ $upstream_response_time ] $bytes_sent';
    
    proxy_buffering off;
    resolver 127.0.0.1;
    aio sendfile;

    output_buffers   32 512k;
    sendfile_max_chunk  128k;
    postpone_output  1460;
    server_names_hash_bucket_size 64;

    reset_timedout_connection on;

    include       mime.types;
    default_type  application/octet-stream;
    proxy_read_timeout 20;
    proxy_send_timeout 10; 
    proxy_connect_timeout 5;

    # log options
    log_format main      '$remote_addr - $remote_user [$time_local] '
                         '"$request" $status $bytes_sent '
                         '"$http_referer" "$http_user_agent" '
                         '"$gzip_ratio" "$request_time"';

    # nginx options
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         off;
    gzip_http_version 1.0;
    gzip             off;
    gzip_min_length  1000;
    gzip_proxied     any;
    gzip_types text/plain application/xhtml+xml text/xml application/xml
application/xml+rss text/json;
    gzip_comp_level  5;


    # fastcgi
    fastcgi_intercept_errors    on;
    fastcgi_max_temp_file_size 0;
    fastcgi_connect_timeout 3;
    fastcgi_read_timeout 15;
    fastcgi_send_timeout 10;

################################################################################


    server {
        listen       199.216.115.123:80 accept_filter=httpready;
        server_name  199.216.115.123;

        access_log off;

        location ~ index\.php$ {
            fastcgi_pass   unix:/tmp/fastcgi_sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME 
/home/domain.com/public_html$fastcgi_script_name;
            include        fastcgi_params;
        }

        location / {
            root   /home/domain.com/public_html;
            index  index.php index.html index.htm;
        }

    }

################################################################################
################################################################################
################################################################################
################################################################################
}

php-fpm:

[global]
pid = /var/run/php-fpm.pid
log_level = warning
emergency_restart_interval = 10m

[www]
listen = /tmp/fastcgi_sock
user = www
group = www
pm = static
pm.max_children = 1000
;pm.start_servers = 40
pm.min_spare_servers = 5
pm.max_spare_servers = 1000
pm.max_requests = 1000
request_slowlog_timeout = 30s
slowlog = /var/log/php-fpm.log.slow
rlimit_files = 200000
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f
www at my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M

php.ini:
output_buffering = 131072
engine = On
zend.ze1_compatibility_mode = Off
asp_tags = Off
precision    =  14
y2k_compliance = On
zlib.output_compression = Off
unserialize_callback_func=
serialize_precision = 100
allow_call_time_pass_reference = Off
safe_mode = On
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
expose_php = On
max_execution_time = 300     ; Maximum execution time of each script, in
seconds
max_input_time = 300	; Maximum amount of time each script may spend
parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 32M      ; Maximum amount of memory a script may consume
(128MB)
error_reporting  =  E_ERROR
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
track_errors = Off
variables_order = "GPCS"
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 8M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
enable_dl = On
cgi.fix_pathinfo=0
file_uploads = Off
upload_max_filesize = 50M
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 120
define_syslog_variables  = Off
[SQL]
sql.safe_mode = Off
[MySQL]
mysql.allow_persistent = On
mysql.connect_timeout = 120
mysql.trace_mode = Off
[MySQLi]
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.reconnect = Off
[Session]
session.save_handler = files
session.save_path = "/tmp"
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly = 
session.serialize_handler = php
session.gc_probability = 0
session.gc_divisor     = 1000
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400

disable_functions =
symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,passthru,escapeshellarg,escapeshellcmd,shell_exec,myshellexec,c99_buff_prepare,c99_sess_
put,fpassthru

Posted at Nginx Forum: http://forum.nginx.org/read.php?21,218467,218467#msg-218467



Подробная информация о списке рассылки nginx-ru