A
A
Andrey2015-12-12 18:47:37
Nginx
Andrey, 2015-12-12 18:47:37

Sometimes a long response from the subdomain. nginx spools up?

Good evening.
There is a subdomain static.mysite.com
from time to time a long response from it. On it are avatars and other pictures.
But no, sometimes there is a long wait on static.mysite.com on mysite.com (loading img)
At first I thought it was necessary to proxy as they did with apache. But even if you upload a 16x16px image weighing 5kb to static.mysite.com and go to static.mysite.com/image16.png in the browser and press f5 10 times in 7 cases it will be displayed immediately and in 3x it will be loaded for a long time (waiting) as if something blunts =(
nginx.conf:

user apache;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
timer_resolution 100ms; 
worker_rlimit_nofile 131072;
worker_processes 8;
events {
    worker_connections  65536;
    multi_accept        on;
    use                 epoll;
}
http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;
sendfile        on;
tcp_nopush     on;
tcp_nodelay on;
keepalive_timeout  65;
types_hash_max_size 2048;
server_tokens off;
reset_timedout_connection on; 
  
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain application/xml application/x-javascript text/javascript text/css text/json;
gzip_disable "msie6";
gzip_comp_level 3;

include /etc/nginx/conf.d/*.conf;
include /usr/local/ispmgr/etc/nginx.domain;
  client_max_body_size 16M;
        client_body_buffer_size 128k; 
  log_format isp '$bytes_sent $request_length';

}

static.mysite.com.conf:
server {
  server_name static.mysite.com;
  root /var/www/user/data/www/static.mysite.com;
  listen xxx.xxx.xxx.xx;
  charset WINDOWS-1251;
  #disable_symlinks if_not_owner from=$root_path;
  set $root_path /var/www/user/data/www/static.mysite.com;
  error_page 403 400 404 = http://mysite.com/404.php;

location ~* ^.+\.(jpg|jpeg|gif|png|ico|svg|js|css|txt|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
                   #access_log off;
                   expires 7d;
}
}

default.conf:
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
        location /nginx_status {
                stub_status on;
                access_log   off;
                allow 127.0.0.1;
                deny all;
        }
}

ping OK:
C:\Users\Great505>ping static.mysite.com Packet
exchange with static.mysite.com [xxx.xxx.xxx.xx] with 32 bytes of data:
Response from xxx.xxx.xxx.xx: number bytes=32 time=123ms TTL=46
Response from xxx.xxx.xxx.xx: number of bytes=32 time=117ms TTL=46
Response from xxx.xxx.xxx.xx: number of bytes=32 time=117ms TTL=46
Response from xxx.xxx.xxx.xx: number of bytes=32 time=117ms TTL=46
Ping statistics for xxx.xxx.xxx.xx:
Packets: sent = 4, received = 4, lost = 0
(0% loss)
Estimated time round-trip in ms:
Minimum = 117ms, Maximum = 123ms, Average = 118ms

In nginx logs, the only thing I see is that my cron script cannot be executed (wget) via http protocol
2015/12/12 12:01:01 [error] 25722#0: *39936015 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xx, server: mysite. com, request: "GET /cron_desk/cron_optimizetable.php?key=dsadsa432rewrew34 HTTP/1.0", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock", host: "mysite .com"
Although there are 5 tables optimize 5 seconds break the next 5 tables optimize and so on.
$i = 0;
$table_r = mysql_query("SHOW TABLES FROM `".$bd_base."`");
while ($tb_r=mysql_fetch_row($table_r)){$i++;
  $status = mysql_query("OPTIMIZE TABLE `".trim($tb_r[0])."`");
  if($i == 5){sleep(5);$i=0;}

Well, in general, yes, a minute goes to the optimize all tables task. How to fix this error so that there is enough time? and fix the response.
Well, kroner, I'm wrong here, of course, I'd rather throw it on the puff interpreter.
Well, what to do with subdomain blunting?
ping -l 1400 -t static.mysite.com average 120
I say again not even output on the main domain, but simply go to the static domain image 5kb static.mysite.com/kartinka.png there may be a long response of 6-7 seconds as -something right now nginx will go to the 502nd. (There is no load at this moment on it).
there is no such problem with the main domain, although they are on the same IP and server and ping from the main domain is the same as from the subdomain, respectively, but it does not blunt and the subdomain blunts.
I forgot to unsubscribe a long time ago I decided. In a comment under the spoiler of solutions.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey, 2016-01-20
@VELIK505

Forgot to unsubscribe. Ruined.
The situation was like this in short, there were a lot of js scripts executing at SetInterval every 10-11 seconds that killed chrome with most of the open tabs, all the static in chrome and the inscription waiting for an available socket began to blunt. The solution is to replace the setintvaral with a settimeout. Setinterval breaks client-side browsers with heaps of scripts. But it's better to go directly to web sockets

V
Vitaly F., 2015-12-12
@FuN_ViT

nginx on windows? It seems like there are pitfalls with this.
Try
or comment
timer_resolution 100ms;

Y
Yuri, 2015-12-12
@xtreme

1. If you measure the packet transit time using ping - bring the packet size closer to the real one of 1500 bytes and do not rely on 4 pings. Because in small packets of 32 or 64 bytes it is difficult to notice network problems.
2. I once chased our web workers with a mop for executing a crown with a web request to PHP. What prevents you from entering the execution of any command into the crontab without jerking the web server? The same PHP can be easily executed from the shell. In addition, sooner or later someone will find your url (the same Google or Yandex will collect data and go to check what is in the url) and then trouble will not be avoided.
3. Can you explain why do OPTIMIZE crown? And how often do you do it?
4. Your response time is long. Server on another continent? For example, you are in Europe and the server is in New York. In this case, there is nothing surprising in dulling.
5. VDS server? In this case, blunting is also quite possible if an HDD is used, or during oversailing at the hoster.
6. Are you using Chrome and your site is also open in adjacent tabs? Please note that Chrome only establishes a maximum of 6 connections to a single host.
It's a good idea to look at the Network tab in the Browser Inspector to see the timings when blunting.
7. Is the image request intercepted by another location? Perhaps the request misses and gets processed, for example, in a PHP script, which itself takes the file from the disk and gives it to nginx.

E
Eugene, 2015-12-12
@Nc_Soft

You are suffering from bullshit

mysqlcheck -u root -pROOT_PASSWORD --auto-repair --optimize --all-databases

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question