Welcome! Log In Create A New Profile

Advanced

speed issues - how to diagnose it correctly?

Posted by yaapelsinko 
speed issues - how to diagnose it correctly?
December 16, 2015 08:56AM
I have a Linux setup with nginx passing requests from external IP to internal application. When I'm accessing it, the app is responding very slow, like tens of seconds. However, in application output log I see it processes requests pretty quick, like building a page in 0.6 sec and then passing linked resources (css, jpg) in under 0.001 second.

However, it often ends in nginx returning 504. Sometimes page is loading only partially. Sometimes load is complete, but too much time it takes.

When 504, it just 504 in nginx log. Like it wasn't nginx fault, but the application one.

What else, apart of reading logs, can I do to diagnose it?
Re: speed issues - how to diagnose it correctly?
December 16, 2015 09:13AM
Could be a timing issue or some kind of (backend) control nginx is (yet) unaware of.

I wrote a small piece about this, which should make thing clearer but not solve it strait away:
=====================
The historical psychology of cgi and proxy(backend).

CGI: has never been (or designed as) a frontend, it always expects to talk to a downstream.

Proxied-backend: has always been a frontend, was never intended to be a backend, in most cases does not know what a frontend is.

Inherently this is where most proxy problems stem from, you have to talk to someone in a different language without knowing which language it speaks (protocol), different continent without knowing where (latency) and not knowing what to expect in return (does it understand me? / return code & error handling)
=====================

Your best bet is to enable debug mode to see which part of the process is 'waiting' for 'what'.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: speed issues - how to diagnose it correctly?
December 18, 2015 11:07PM
I've done some tests and the picture is appears to be the following.

First, the app I'm deploying is an ASP.NET 5 app on Ubuntu machine. As it can only listen on local port (if not involving some root configurations), I'm using nginx to proxy-pass all requests to it from an external port and, optionally, a server name.

According to the app log, the requested page is actually rendered quite fast, then application starts to pass it to nginx, but suddenly stops transmitting data without warning (or nginx stops to read the data, while playing as if it is still listening). And transmission is always cut only when close to the end, so if there is more data, the part of this data can make its way through nginx. And if there is very small amount of data to be passed, then almost nothing is passed at all, just response headers. Nginx seems to be unaware of the transmission stop and just waits it to continue, and once it hits the timeout, it just transmits all the data it received to the moment. For small simple template pages it is just response headers. For the larger page with a couple of kilobytes it is also most of the page's html transmitted, but page is incomplete (no closing body and html tags and some other markup).

I've created an Ubuntu Desktop VM, and configured it just like I did to my server, except one thing - I did not used nginx this time, but just accessing the local port from the local (to the VM) browser, like http://127.0.0.1:5002. The app was working well. But once I've configured a nginx proxy-pass:

server {
listen 8080;
server_name localhost;

proxy_connect_timeout 5;
proxy_send_timeout 5;
proxy_read_timeout 5;
send_timeout 5;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5002;
}
}

and tried to access from outside (like 192.168.0.1:8080, or even locally 127:0.0.1:8080), I've got the same issue again - partial response only after timeout is hit. Timeouts of 5 seconds are introduced so that I don't have to wait 60 or 600 seconds (which I also tried in case the app itself demand more time to answer);

So while the app working on it's own, all seems to be right. When nginx is introduced to the request chain, it behaves like this.

Um. Suggestions? :-/
Re: speed issues - how to diagnose it correctly?
December 19, 2015 12:00AM
Updating nginx 1.4.6 to 1.8.0 didn't help.
Re: speed issues - how to diagnose it correctly?
December 19, 2015 12:28AM
As this topic's doesn't represent exact issue, I've moved relevant info to this: https://forum.nginx.org/read.php?15,263566
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 279
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