2

I have an nginx in front of 5 tornado servers.

When I call one of my Tornado server directly then the results are returned very fast.

But when I call nginx instead, it takes VERY long to return results. On checking the logs I can see that the request comes in as "OPTIONS" into nginx and the selected tornado server almost immediately. But then it takes its own sweet little time after which I see "GET" request in the logs and then the response is returned. Why is there such a long delay between OPTIONS and GET? When calling Tornado directly, OPTIONS and GET request happens back to back very quickly. Do I need to change something on my nginx config file to make the performance better?

My nginx config looks like this:

worker_processes 1;

error_log  logs/error.;

events {
    worker_connections 1024;
}

http {
    # Enumerate all the Tornado servers here
    upstream frontends {
        server 127.0.0.1:5052;
        server 127.0.0.1:5053;
        server 127.0.0.1:5054;
        server 127.0.0.1:5055;
        server 127.0.0.1:5056;
    }

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

    keepalive_timeout 65;

    sendfile on;


    server {
        listen 5050;
        server_name x;

        ssl on;
        ssl_certificate certificate.crt;
        ssl_certificate_key keyfile.key;

        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass https://frontends;
        }
    }
}

And my tornado files have this structure:

import tornado.httpserver
import tornado.ioloop
import tornado.web
from flasky import app
from tornado.wsgi import WSGIContainer
from tornado.ioloop import IOLoop
from tornado.web import FallbackHandler

tr = WSGIContainer(app)

application = tornado.web.Application([
    (r".*", FallbackHandler, dict(fallback=tr)),
])

if __name__ == '__main__':
    http_server = tornado.httpserver.HTTPServer(application, ssl_options={
        "certfile": "certificate.crt",
        "keyfile": "keyfile.key",
    })
    http_server.listen(5056, address='127.0.0.1')
    IOLoop.instance().start()
90abyss
  • 7,037
  • 19
  • 63
  • 94
  • `worker_processes 1;`... You've defeated the purpose of having any multi-instance tornado server – OneCricketeer Mar 13 '17 at 01:51
  • Some hints http://stackoverflow.com/questions/7325211/tuning-nginx-worker-process-to-obtain-100k-hits-per-min#8217856 – OneCricketeer Mar 13 '17 at 01:52
  • @cricket_007 I changed it to "16" now (I've a 16 core VM). Still the same issue :( – 90abyss Mar 13 '17 at 02:31
  • Is it necessary to run SSL over localhost? That second negotiation is probably introducing some delay. – Richard Smith Mar 13 '17 at 08:30
  • I'm using Windows Server 2012. Does nginx have performance issues on Windows? – 90abyss Mar 13 '17 at 18:37
  • @RichardSmith I get an error when the connection goes from https to http. Therefore had to have everything in localhost. – 90abyss Mar 13 '17 at 23:27
  • As a workaround, I deployed my flask app on Apache instead. Seems to be working well so far. Too bad I am stuck with Windows or else I'd definitely have leveraged the power of nginx. – 90abyss Mar 13 '17 at 23:28

0 Answers0