Welcome! Log In Create A New Profile

Advanced

Slow static file serving

Posted by eleshar 
Slow static file serving
October 04, 2011 01:37AM
Having issue with static files being served very slowly, for example a mere 0.3kb png file will take ~9 seconds to load.

I'm running nginx-1.0.8 on ubuntu 11.04 with php-5.3.8 and php-fpm hosting wordpress sites.

This is my nginx.conf

user www-data;
worker_processes 4;
error_log /var/log/nginx/nginx.log info;
pid /var/run/nginx.pid;

worker_rlimit_nofile 8192;

events {
worker_connections 1024;
multi_accept on;
use epoll;
}

http {
include mime.types;
include fastcgi_params;
default_type application/octet-stream;

server_name_in_redirect off;
server_names_hash_max_size 10240;
server_names_hash_bucket_size 1024;
server_tokens off;
aio on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
gzip on;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_http_version 1.1;
gzip_min_length 1000;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_types text/plain text/xml text/css application/x-javascript application/xml image/png image/x-icon image/gif image/jpeg application/xml+rss text/javascript application/atom+xml;
ignore_invalid_headers on;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
reset_timedout_connection on;
connection_pool_size 256;
client_header_buffer_size 256k;
large_client_header_buffers 4 256k;
client_max_body_size 25M;
client_body_buffer_size 128k;
request_pool_size 32k;
output_buffers 4 32k;
postpone_output 1460;
proxy_temp_path /tmp/nginx_proxy/;
client_body_in_file_only on;
log_format bytes_log "$msec $bytes_sent .";

fastcgi_connect_timeout 180;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
if_modified_since before;

upstream php {
server unix:/var/run/php5-fpm.sock;
}

server {

listen 8080;
server_name domain.com;

root /var/www/domain.com;
index index.php index.html;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 30d;
break;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}


}

Does anyone have potential insight into what the issue might be?
Re: Slow static file serving
December 13, 2011 05:32AM
I'm sorry I can't answer your question, but I have a similar problem with an almost-identical setup. Here's my details!

I've got extremely slow Wordpress under ISPConfig 3.0.4.1, but unlike the post above, it's the back end only. I updated to WP 3.3 this morning, but still the same.

The strange thing is, I'm running a personal WP install on a free "tiny" instance on Amazon S3 with a similar config and low memory, and it flies along. Which is what makes it even more difficult to diagnose.

Anyway, here's a whole load of details:

Ubuntu 11.10
Nginx 1.0.10
php5-fpm 5.3.8

I've got a 256Mb VPS running a Zen Cart store and phpbb3, both in different php-fpm pools. There's hardly anything running except the essentials and both those sites absolutely rocket along. As does the front end of the Wordpress site, when W3TC accelerated.

BUT.... the admin side takes 6-10 seconds to do anything.
There's nothing in the mysql slow log, or the php-fpm error log, the load doesn't spike, and the memory usage doesn't shoot up (but see below about memory).

The first time it loads, at wp-admin/options.php it shows a very long page that looks wrong, with line after line of stuff like...

active_plugins SERIALIZED DATA

Here's the main items from ps_mem.py

----------------------------------
732.0 KiB + 87.5 KiB = 819.5 KiB bash
2.1 MiB + 369.0 KiB = 2.4 MiB fail2ban-server
1.8 MiB + 2.0 MiB = 3.9 MiB nginx (5)
5.1 MiB + 12.8 MiB = 17.9 MiB php5-fpm (29)
87.8 MiB + 149.0 KiB = 88.0 MiB mysqld
---------------------------------
116.2 MiB
=================================

Here's the load average pretty much all the time:
load average: 0.48, 0.53, 0.51

And here's the output from free -m
----------------------------------
total used free shared buffers cached
Mem: 241 202 38 0 3 49
-/+ buffers/cache: 149 92
Swap: 511 29 482
----------------------------------


Here's the nginx.conf, including the cloudflare real_ip settings (tried without cloudflare too), and also the rewrite required to make permalinks work under nginx:

----------------------------------
server {
listen 31.172.x.x:80;


server_name mysite.co.uk www.mysite.co.uk www.my-site.co.uk my-site.co.uk;

root /var/www/mysite.co.uk/web;

index index.html index.htm index.php index.cgi index.pl index.xhtml;

error_page 400 /error/400.html;
error_page 401 /error/401.html;
error_page 403 /error/403.html;
error_page 404 /error/404.html;
error_page 405 /error/405.html;
error_page 500 /error/500.html;
error_page 502 /error/502.html;
error_page 503 /error/503.html;

error_log /var/log/ispconfig/httpd/mysite.co.uk/error.log;
access_log /var/log/ispconfig/httpd/mysite.co.uk/access.log combined;

## Disable .htaccess and other hidden files
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location /stats {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file /var/www/clients/client3/web9/.htpasswd_stats;
}

location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web9.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_intercept_errors on;
}

set_real_ip_from 204.93.240.0/24;
set_real_ip_from 204.93.177.0/24;
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
real_ip_header CF-Connecting-IP;
client_max_body_size 28M;
client_body_buffer_size 128k;

if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
break;
}
#include /var/www/mysite.co.uk/web/nginx.conf;
}
----------------------------------

Here's the php5-fpm pool conf for that site:

----------------------------------
[web9]

listen = /var/lib/php5-fpm/web9.sock
listen.owner = web9
listen.group = client3
listen.mode = 0660

user = web9
group = client3

pm = dynamic
pm.max_children = 4
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 2

chdir = /

php_admin_value[open_basedir] = /var/www/clients/client3/web9/web:/var/www/clients/client3/web9/tmp:/var/www/mysite.co.uk/web:/srv/www/mysite.co.uk/web:/usr/share/php5:/tmp:/usr/share/phpmyadmin:/etc/phpmyadmin:/var/lib/phpmyadmin
php_admin_value[session.save_path] = /var/www/clients/client3/web9/tmp
php_admin_value[upload_tmp_dir] = /var/www/clients/client3/web9/tmp

php_admin_value[date.timezone] = "UTC"
php_admin_value[post_max_size] = 28M
php_admin_value[session.gc_maxlifetime] = 604800
php_admin_value[upload_max_filesize] = 28M
php_admin_flag[display_errors] = off
php_admin_flag[display_startup_errors] = off
php_admin_flag[log_errors] = off
php_admin_flag[ignore_repeated_errors] = off
php_admin_flag[ignore_repeated_source] = off
php_admin_value[memory_limit] = 32M
----------------------------------

That last line about memory limit is new, but made no difference either.

I had to make changes to /etc/php5/conf.d/suhosin.ini as advised by phpmyadmin, and also upped the memory limit for WP as I was getting
"ALERT - script tried to increase memory_limit to 268435456 bytes which is above the allowed value".

----------------------------------
; configuration for php suhosin module
extension=suhosin.so
suhosin.executor.include.whitelist="phar"
suhosin.request.max_vars=2048
suhosin.post.max_vars=2048
suhosin.request.max_array_index_length=256
suhosin.post.max_array_index_length=256
suhosin.request.max_totalname_length=8192
suhosin.post.max_totalname_length=8192
suhosin.get.max_value_length=1024
suhosin.memory_limit=128M
----------------------------------

I reduced the memory limit in wp-config.php as shown below.

----------------------------------
define('WP_MEMORY_LIMIT', '32M');
define('WP_MAX_MEMORY_LIMIT', '32M');
----------------------------------

Although, I've changed these limits from 256 to 128 to 64 to 32 and it makes NO difference to the front or back end speeds.

I changed the theme to default, turned off all the plugins, changed all the mysql tables to to innodb and followed the recommendations of mysqltuner (even though, as I said, there's nothing about slow mysql in the logs I can see).

I've tried changing php-fpm from socket to port and back, and so on and so forth. Not really sure what else to do now - can anyone spot anything here or advise?

And yes, I might be running a bit tight on memory, but then why does Zen Cart and phpbb running with a big DB load pages sub 200ms?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready