Welcome! Log In Create A New Profile

Advanced

Windows php cgi perfomance

Posted by Igor Kuznetsov 
Windows php cgi perfomance
March 25, 2016 09:50AM
Hi

I have

http://nginx-win.ecsds.eu/ version 1.9.13.1
Windows server 2012r2 VDS with two 200% time cpu cores, 4 gb ram
php 7.0.4
opcache enabled, about 95% hit

Story is that when i start free test from loadimpact with 50 virtual users on site main page i have about 40% cpu used with php-cgi.exe..

Is that normal ? I tryed cgi cache. Its ok with it, but its very bad idea to use cgi cache with online shop..

What can i tune in that config ?

Thank you

worker_processes 1;

error_log logs/error.log;
#error_log D:/Server/nginx/logs/error.log;

events {
worker_connections 8192;
multi_accept on;
}


http {
#include /nginx/conf/naxsi_core.rules;
include mime.types;
default_type application/octet-stream;



tcp_nodelay on;
tcp_nopush on;
sendfile on;


server_names_hash_bucket_size 128;
map_hash_bucket_size 64;


reset_timedout_connection on;
send_timeout 5;

client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 30;
keepalive_requests 100;
server_tokens off;

#fastcgi_cache_path D:/Server/nginx_cache/ levels=1:2 keys_zone=ZONE1:250m inactive=60m;
#fastcgi_cache_key "$scheme$request_method$host$request_uri";
#fastcgi_cache_use_stale error timeout invalid_header http_500;
#fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;


server{
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}




server
{


listen 443 ssl http2;
listen [::]:443 ssl http2;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
access_log off;
root D:/Server/htdocs/;

server_name 123123.ru;

index index.php;


gzip on;
gzip_vary on;
gzip_static off;
gzip_min_length 1024;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript ;
gzip_disable "msie6";

ssl_certificate D:/Server/ssl/cert_chain.crt;
ssl_certificate_key D:/Server/ssl/key.key;
ssl_trusted_certificate D:/Server/ssl/COMODORSADomainValidationSecureServerCA.crt;
ssl_dhparam D:/Server/ssl/dhparams.pem; #openssl dhparam -out dhparams.pem 2048
ssl_session_timeout 1h;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
ssl_prefer_server_ciphers on;
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;



try_files $uri $uri/ /index.php?$query_string;






location ~ \.php$ {
root D:/Server/htdocs/;
fastcgi_pass 127.0.0.1:9123; # single backend process

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;



}


location /index.php {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
}

# for install only
location /install.php {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
}

location /api.php {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
}

location ^~ /wa-data/protected/ {
#return 403;
#X-Accel-Redirect
internal;
}

location ~* ^/wa-(log|config|cache|system)/ {
return 403;
}

location ~* ^/wa-data/public/contacts/photo/[0-9]+/ {
root /var/www/fw/;
access_log off;
expires 30d;
error_page 404 = @contacts_thumb;
}

location @contacts_thumb {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
fastcgi_param SCRIPT_NAME /wa-data/public/contacts/photos/thumb.php;
fastcgi_param SCRIPT_FILENAME $document_root/wa-data/public/contacts/photos/thumb.php;
}

# photos app
location ~* ^/wa-data/public/photos/[0-9]+/ {
access_log off;
expires 30d;
error_page 404 = @photos_thumb;
}

location @photos_thumb {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
fastcgi_param SCRIPT_NAME /wa-data/public/photos/thumb.php;
fastcgi_param SCRIPT_FILENAME $document_root/wa-data/public/photos/thumb.php;
}

# end photos app

# shop app
location ~* ^/wa-data/public/shop/products/[0-9]+/ {
access_log off;
expires 30d;
error_page 404 = @shop_thumb;
}

location @shop_thumb {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
fastcgi_param SCRIPT_NAME /wa-data/public/shop/products/thumb.php;
fastcgi_param SCRIPT_NAME /wa-data/public/shop/products/thumb.php;
fastcgi_param SCRIPT_FILENAME $document_root/wa-data/public/shop/products/thumb.php;
}

# end shop app

# mailer app
location ~* ^/wa-data/public/mailer/files/[0-9]+/ {
access_log off;
error_page 404 = @mailer_file;
}

location @mailer_file {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9123;
#fastcgi_pass myLoadBalancer;
fastcgi_param SCRIPT_NAME /wa-data/public/mailer/files/file.php;
fastcgi_param SCRIPT_FILENAME $document_root/wa-data/public/mailer/files/file.php;
}

# end mailer app

location ~* ^.+\.(js|css|jpg|jpeg|gif|png|svg|ttf|eot|otf|woff|woff2)$ {
access_log off;
expires 30d;
}


}
}
Re: Windows php cgi perfomance
March 25, 2016 02:29PM
Igor Kuznetsov Wrote:
-------------------------------------------------------
> Story is that when i start free test from loadimpact with 50 virtual
> users on site main page i have about 40% cpu used with php-cgi.exe..
>
> Is that normal ? I tryed cgi cache. Its ok with it, but its very bad
> idea to use cgi cache with online shop..

Who told you its bad to use a cache? everyone uses caching with php.

> What can i tune in that config ?

Use a pool of php-cgi just like the example config (nginx-win.conf) shows you (upstream myLoadBalancer)

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
March 25, 2016 04:38PM
Igor Kuznetsov Wrote:
-------------------------------------------------------
> What can i tune in that config ?

> worker_processes 1;

Use 2 or 4.

> multi_accept on;

Set off

> sendfile on;

Set off

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
March 26, 2016 09:22AM
why off ? every tutorial i see - they are on..
Re: Windows php cgi perfomance
March 26, 2016 07:15PM
We've re-engineered the software and we recommend it to be off.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
March 28, 2016 02:22PM
ok.. looks like i almost done with cache

Little problem is that "Viewed" list is not working

There is a cookie that have a data about viewed items on site, it ok, cookie is updating while i using site, but when i go to site main page "Viewed" its not changing

But if i will click to "Viewed" list i will all of them

Hot to fix it ?

location ~ \.php$ {
root D:/Server/htdocs/;
fastcgi_pass 127.0.0.1:9123; # single backend process
#fastcgi_pass myLoadBalancer; # or multiple, see example above
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

fastcgi_index index.php;
add_header X-Cache $upstream_cache_status;
fastcgi_cache YOURAPP;
fastcgi_cache_bypass $fastcgi_skipcache;
fastcgi_no_cache $fastcgi_skipcache;



fastcgi_pass_header Cookie;
fastcgi_cache_key "$server_addr:$server_port$request_uri|$cookie_phpsessid";
set $fastcgi_skipcache 0;

if ($request_method = POST) {
set $fastcgi_skipcache 1;
}

if ($query_string != "")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(webasyst/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(cart/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(orders/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(profile/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(login/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(my/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(search/)")
{
set $fastcgi_skipcache 1;
}



Edited 1 time(s). Last edit at 03/28/2016 02:25PM by Igor Kuznetsov.
Re: Windows php cgi perfomance
March 28, 2016 02:59PM
Igor Kuznetsov Wrote:
-------------------------------------------------------
> ok.. looks like i almost done with cache
>
> Little problem is that "Viewed" list is not working
>
> There is a cookie that have a data about viewed items on site, it ok,
> cookie is updating while i using site, but when i go to site main page
> "Viewed" its not changing
>
> But if i will click to "Viewed" list i will all of them

You will to be more explicit with the problem you are having, also use Curl to see what is coming back and if its what you expected.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
March 29, 2016 09:22AM
Problem solved

http {

fastcgi_cache_path D:/Server/nginx_cache levels=1:2 keys_zone=YOURAPP:100m inactive=60m;
}

location ~ \.php$ {
root D:/Server/htdocs/;
fastcgi_pass 127.0.0.1:9123; # single backend process
#fastcgi_pass myLoadBalancer; # or multiple, see example above
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

include D:/Server/nginx/conf/cgi.conf;

}

cgi.conf :

fastcgi_index index.php;
add_header X-Cache $upstream_cache_status;
fastcgi_cache YOURAPP;
fastcgi_cache_bypass $fastcgi_skipcache;
fastcgi_no_cache $fastcgi_skipcache;


fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;phpsessid будет находится в переменной $cookie_phpsessid
fastcgi_cache_key "$server_addr:$server_port$request_uri|$cookie_phpsessid";


fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

set $fastcgi_skipcache 0;

if ($request_method = POST) {
set $fastcgi_skipcache 1;
}

if ($query_string != "")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(webasyst/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(cart/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(orders/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(profile/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(login/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(my/)")
{
set $fastcgi_skipcache 1;
}

if ($request_uri ~* "/(search/)")
{
set $fastcgi_skipcache 1;
}
Re: Windows php cgi perfomance
April 10, 2016 02:09PM
some times i have

[error] 1104#1616: *1821 upstream timed out

what can it be ?
Re: Windows php cgi perfomance
April 10, 2016 04:13PM
Igor Kuznetsov Wrote:
-------------------------------------------------------
> some times i have
>
> [error] 1104#1616: *1821 upstream timed out
>
> what can it be ?

This is a repeat answer:

#fastcgi_pass myLoadBalancer; # or multiple, see example above

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
April 13, 2016 08:03AM
But why its time out ? Site is on testing and i am the only user.. Cgi cache is turned off for now

Currently i have 1 php service using that config

<service>
<id>php2</id>
<name>php2</name>
<description>php2</description>

<executable>D:\Server\php_nginx\php-cgi.exe</executable>
<startargument>-b</startargument>
<startargument>127.0.0.1:9123</startargument>

<stopexecutable>taskkill.exe</stopexecutable>
<stopargument>/f</stopargument>
<stopargument>/IM</stopargument>
<stopargument>php-cgi.exe</stopargument>

<logpath>D:\Server\php_nginx\logs</logpath>
<logmode>roll</logmode>
<depend></depend>
</service>

Should i install 1 more services with different ports in case of

upstream myLoadBalancer {
server 127.0.0.1:9123 weight=1 fail_timeout=5;
server 127.0.0.1:9124 weight=1 fail_timeout=5;
server 127.0.0.1:9125 weight=1 fail_timeout=5;
least_conn;
}

?
Re: Windows php cgi perfomance
April 13, 2016 08:22AM
Igor Kuznetsov Wrote:
-------------------------------------------------------
> Should i install 1 more services with different ports in case of
>

Here we use 10 in one pool which seems to be the right amount for the last 2 years.

Have a look at http://nginx-win.ecsds.eu/download/Install_nginx_php_services.zip
how this pool is created / managed and used in nginx.conf

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
April 19, 2016 12:02PM
Bat files in 2016 year is very strange, but i used it as example and wrote my own service with c# that uses powershell to start/stop cgi process

so, same 10 php-cgi.exe as in example...

For ($i = 9123; $i -lt 9132;$i++)
{
[string]$arg='-b 127.0.0.1:'+$i
Start-Process -FilePath 'D:\Server\php_nginx\php-cgi.exe' $arg -NoNewWindow
}

and still sometimes i have

2016/04/19 18:50:47 [warn] 1980#1504: *395 upstream server temporarily disabled while connecting to upstream, client: 95.215.110.151, server: 123.ru, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9132", host: "123.ru"

2016/04/19 18:50:47 [error] 1980#1504: *395 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 95.215.110.151, server: 123.ru, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9132", host: "123.ru"

2016/04/19 18:56:26 [warn] 536#2632: *430 upstream server temporarily disabled while connecting to upstream, client: 95.215.110.151, server: osmosnadom.ru, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9132", host: "123.ru"

2016/04/19 18:56:26 [error] 536#2632: *430 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 95.215.110.151, server: 123.ru, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9132", host: "123.ru"

there are no php error even with error_reporting = E_ALL...



Edited 1 time(s). Last edit at 04/19/2016 12:03PM by Igor Kuznetsov.
Re: Windows php cgi perfomance
April 19, 2016 01:11PM
If an upstream times out it is simply doing something which is taking more time then expected, most likely some php code misbehaving.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
April 25, 2016 01:30PM
btw it was a bug in startup script

For ($i = 9123; $i -lt 9132;$i++)

should be For ($i = 9123; $i -lt 9133;$i++) ....


and one more question - will http://nginx-win.ecsds.eu/ version support windows service in native mode? reason is that server windows is optimized for services...
Re: Windows php cgi perfomance
April 27, 2016 03:46AM
Igor Kuznetsov Wrote:
-------------------------------------------------------
> and one more question - will http://nginx-win.ecsds.eu/ version
> support windows service in native mode? reason is that server windows
> is optimized for services...

nginx already runs in native mode. The term 'service' has no nginx relation with being optimized, nginx for Windows is already tied in to the kernel at various levels at runtime to maximize performance.

ea. you can wrap any program in to a service and call it a service but the program has to be written to co-operate with the kernel at service levels before it is really performing as a service, the fact we use a service wrapper has nothing to do with this design.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Windows php cgi perfomance
April 28, 2016 06:31AM
*nginx already runs in native mode*

i mean i can call *nginx.exe -install* and it will be in services without handmade or 3party tools.like apache

will it ? sometime?
Re: Windows php cgi perfomance
April 28, 2016 10:56AM
No, there is no service install support other then the installer we have online.
A program running normally or as a service is no more then a flag at kernel level which we control anyway.

There are always additional things that need to be done before starting and stopping which a regular service is unable to do, using a batchfile launched as a service allows everything and it won't effect nginx being seen as a service as it is run in service space.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 299
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready