Nginx is very slow
June 25, 2009 07:29AM
Hello,

Nginx is very slow on my server... it takes 10 sec for every page to load!

what can it be? how to fix it?

error_log
[code]
2009/06/25 14:22:57 [error] 31428#0: *91456 upstream timed out (110: Connection timed out) while connecting to upstream, client: 85.65.217.223, server: _, request: "GET /index.php?showtopic=202969 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.us", referrer: "http://www.mydomain.us/index.php?showforum=621"
2009/06/25 14:22:59 [error] 31431#0: *97658 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 79.111.184.73, server: _, request: "GET /index.php?showforum=341 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.us", referrer: "http://www.mydomain.com/"
2009/06/25 14:22:59 [error] 31431#0: *98003 open() "/usr/share/nginx/html/uploads/av-41748.jpg" failed (2: No such file or directory), client: 89.101.27.115, server: _, request: "GET /uploads/av-41748.jpg HTTP/1.1", host: "www.mydomain.us", referrer: "http://www.mydomain.us/index.php?showtopic=144471"
2009/06/25 14:22:59 [error] 31432#0: *91136 upstream timed out (110: Connection timed out) while connecting to upstream, client: 79.180.206.199, server: _, request: "GET /index.php?showtopic=161379 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.us", referrer: "http://www.mydomain.us/index.php?showforum=627"
2009/06/25 14:23:00 [error] 31431#0: *95539 upstream timed out (110: Connection timed out) while connecting to upstream, client: 84.111.125.207, server: _, request: "GET /index.php?showtopic=201564 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.mydomain.us", referrer: "http://www.mydomain.us/index.php?showforum=626"
[/code]

nginx.config

[code]
worker_processes 6;
worker_rlimit_nofile 10240;

events {
worker_connections 5024;
}
[/code]

Regards,
Nginx Fan
Re: Nginx is very slow
June 25, 2009 07:31AM
forget to mention...

i notice that every time I restart php-cgi
[code]
/etc/init.d/php_cgi restart
[/code]

it works faster for a half minute
can it be the php_cgi?

[u]this is what i have in php_cgi[/u]
[code]
#!/bin/sh
#
# php-cgi - php-fastcgi swaping via spawn-fcgi
#
# chkconfig: - 85 15
# description: Run php-cgi as app server
# processname: php-cgi
# config: /etc/sysconfig/phpfastcgi (defaults RH style)
# pidfile: /var/run/php_cgi.pid
# Note: See how to use this script :
# http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

spawnfcgi="/usr/bin/spawn-fcgi"
php_cgi="/usr/bin/php-cgi"
prog=$(basename $php_cgi)
server_ip=127.0.0.1
server_port=9000
server_user=nginx
server_group=nginx
server_childs=5
pidfile="/var/run/php_cgi.pid"

# do not edit, put changes in /etc/sysconfig/phpfastcgi
[ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi

start() {
[ -x $php_cgi ] || exit 1
[ -x $spawnfcgi ] || exit 2
echo -n $"Starting $prog: "
daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}
retval=$?
echo
return $retval
}

stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $prog -QUIT
retval=$?
echo
[ -f ${pidfile} ] && /bin/rm -f ${pidfile}
return $retval
}

restart(){
stop
sleep 2
[...]
[/code]
Re: Nginx is very slow
August 11, 2009 05:53PM
According to your log files it looks like you have entered a restrictive value for time outs, could you provide the rest of your nginx.conf?

You have far too much worker processes, set the amount of worker processes to the amount of cpu cores your web server runs on. To check how many cpu cores you have enter the following comment in your shell:
[code]
$ cat /proc/cpuinfo | grep processor | wc -l
[/code]

Next I would recommend to use PHP-FPM if your server is still slow: http://php-fpm.org/Main_Page

--------------------------------------------------------------------------------
//richard.fussenegger.info
//movlib.org



Edited 1 time(s). Last edit at 08/11/2009 05:55PM by Fleshgrinder.
Re: Nginx is very slow
August 17, 2009 08:59PM
I have similar situation and I get almost the same errors in the error_log, although I'm using php-fpm:

[code]
user www-data www-data;
worker_processes 6;

error_log logs/error.log error;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

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

client_max_body_size 5m;

access_log on;
#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
server_tokens off;
gzip on;
gzip_types text/plain text/css application/x-javascript application/xml application/xml+rss;

server {
server_name server.com;
rewrite ^(.*) http://www.server.com$1 permanent;
}

server {

listen 80;
server_name www.server.com;
server_name_in_redirect off;

location / {
expires 30d;
root /var/www;
index index.html index.htm index.php;
}

error_page 404 /404.html;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
root /var/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}

}
}

[/code]

The server's CPU has only one core.
I also have set php-fpm max_children to 45.
XCache is installed also with 0.5GB memory set.

My site has many static files as content, I wonder if setting up second nginx as reverse-proxy serving static content and sending dynamic requests to the first one would help improve the speed.



Edited 3 time(s). Last edit at 08/17/2009 09:05PM by raffael.
Re: Nginx is very slow
August 19, 2009 05:49PM
OK, I've installed stub status module (great thing).
This is what I get most of the time:

[code]
Active connections: 51
server accepts handled requests
119 119 619
Reading: 0 Writing: 5 Waiting: 46
[/code]

Isn't there a bit too much waiting connections to the writing ones?



Edited 1 time(s). Last edit at 08/19/2009 05:49PM by raffael.
Re: Nginx is very slow
September 05, 2009 04:54AM
I can't tell you what the output of the stub status module means, never used it.

If your cpu count is only one, only use 1 or 2 worker_processes. Try increasing the worker_connections instead - maybe 2048.

You don't have create a second nginx server or reverse proxy or something, you can tell your existing server that it should deliver static files directly. The following goes into your server { ... } block:
[code]
# that's my rule set if you don't have svg or svgz files, delete it
location ~* ^.+.(bmp|jpg|jpeg|gif|css|png|js|ico|svg|svgz)$ {
access_log off;
expires max;
}
[/code]

More info on the expires directive: http://wiki.nginx.org/NginxHttpHeadersModule#expires

--------------------------------------------------------------------------------
//richard.fussenegger.info
//movlib.org



Edited 1 time(s). Last edit at 09/05/2009 04:55AM by Fleshgrinder.
Re: Nginx is very slow
October 08, 2009 11:50AM
I have the same problem too, it even takes more than 15 seconds.

I tried the suggestions here but no luck yet.

[url=http://www.treadmillskiva.com]Eric Deko[/url]
Re: Nginx is very slow
October 15, 2009 09:29PM
I have the same problem too,

error_log :[b]failed (110: Connection timed out) while connecting to upstream, client:[/b]

nginx.conf such as:
[code]
worker_processes 8;
events {
use epoll;
worker_connections 51200;
}
[/code]

Is i set worker_connections to height???
Re: Nginx is very slow
December 10, 2009 05:04PM
I have the same problem and it is driving me crazy.

When I reboot, it works super fast for like 30 - 60 sec, then hude delays ...
I think it must be fast cgi but dont' know where it is going wrong.
Re: Nginx is very slow
December 20, 2009 02:15PM
I'm having a similar issue, on a very high-traffic site, and as best I can tell, FASTCGI doesn't know that PHP has timed out, so it just waits for a response indefinately. These requests then create a long queue, and your requests just get longer and longer.

I've done two things:

1) Reduce the timeout in the FASTCGI_PARAMS
fastcgi_send_timeout 10;
fastcgi_read_timeout 10;

This may kill some connections initially, but then brings the site back to some sane level of performance.

2) Reboot PHP_CGI using cron on an hourly basis.

Best I can do, both are terrible solutions, but they seem to work for now.

Would be great to get some advice from someone who can dig deeper into the issue...
Re: Nginx is very slow
July 20, 2011 09:50AM
Got the same problem

The problem was with spawn-fcgi(custom build from scratch) , after reinstalling it from distribution everything works just fine.
Re: Nginx is very slow
February 06, 2012 10:05PM
I have the same problem. Still could not solve.
Re: Nginx is very slow
May 21, 2012 09:47PM
nginx is coping with its share of connecyions, but the php manager is overloaded.

Raise the resources there.

HTH,
Gerardo
fas
Re: Nginx is very slow
July 26, 2012 02:57PM
I have the same problem...

This is my config...

user www-data;
worker_processes 2;
worker_rlimit_nofile 10480;

pid /var/run/nginx.pid;

events {
worker_connections 8024;
multi_accept off;
use epoll;
}


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

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

keepalive_timeout 10;

========================================================================================================

#
# Settings for php-cgi in external FASTCGI Mode
#

# Should php-fastcgi run automatically on startup? (default: no)

START=yes

# Which user runs PHP? (default: www-data)

EXEC_AS_USER=www-data

# Host and TCP port for FASTCGI-Listener (default: localhost:9000)

FCGI_HOST=127.0.0.1
FCGI_PORT=9000

# Environment variables, which are processed by PHP

PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000

=========================================================================================================

Can you tell me how to fix it?

Thanks a lot!!!

Sorry for my bad english...
Re: Nginx is very slow
October 01, 2015 06:35AM
I have the same problem...
plz help me


worker_processes 6;

worker_rlimit_nofile 30000;

events {
worker_connections 8192;
}
Re: Nginx is very slow
October 01, 2015 07:33AM
http://forum.nginx.org/read.php?1,252530

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx is very slow
July 05, 2018 03:55AM
I am new to Nginx.

I have a brand new installation of Nginx on my Windows Server 2012 R2.

This is a stable Windows version of Nginx from Kevin Worthington, 1.14.0 Release of Nginx for Windows.
Built by Kevin Worthington on Windows 7 Ultimate 64-bit using Cygwin.

At first Nginx was very fast without PHP and MySQL, I was very happy.

But after I installed PHP version 5.6.31 and MySQL version: 8.0.11 I noticed that Nginx is surprisingly slow with PHP scripts.

I have to wait for 1 minute or more to open my website http://tayskaya-kosmetika.ru which is an exact copy of my website https://superbank.ru

The original website https://superbank.ru is hosted on another server running Apache web server and is fully loaded in just 5 seconds.

What is wrong with my Nginx, PHP, MySQL setup?

The logs are attached.

If you need any other logs please let me know.

I am also concerned about the alert in the Nginx Error log:
[alert] 384#0: recvmsg() returned invalid ancillary data level 1 or type 0

What shall I do to fix this problem?
Attachments:
open | download - nginx.conf (3.6 KB)
open | download - error.log (148.9 KB)
Re: Nginx is very slow
July 05, 2018 04:09AM
PHP.INI file is here
Attachments:
open | download - php.ini (74.2 KB)
Re: Nginx is very slow
July 06, 2018 01:51AM
I want to update my previous post.

It appears that NGINX server is not responsible for this terrible slowness of my website.

I have just switched my website, http://tayskaya-kosmetika.ru , to the integrated IIS server on my VDS hosting Windows Server 2012 R2.

Again it takes about 1 or 2 minutes to open the website. Probably this is the issue with PHP - FastCGI and system resources being limited by the VDS hosting provider. Anyway it is declared as 2 cores of Intel Xeon E5 @ 2.2 GHz with 2 Gb of RAM and 40 Gb SSD disk.
The size of MySQL database is 226 MiB with the total of 2.2 Million rows altogether.

The exact copy of the same website, https://superbank.ru , hosted on a Shared Hosting with another provider is fully loaded in just 5 seconds!

But the hosting provider is complaining that my website is consuming too much MySQL time. That's why I am thinking of VDS /VPS hosting instead of Shared Hosting.
Re: Nginx is very slow
July 06, 2018 02:04AM
With any cgi application (like php is) you need to create a pool to handle high loads as cgi is considered blocking, for Windows I have created a long time ago a pool configuration of 10 including installation, see sig for details.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Nginx is very slow
July 06, 2018 03:01AM
Thank you for your advice. I will study this subject.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 107
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready