pts
pts

Reputation: 87291

How to make uwsgi --http-to be able to handle multiple responses at the same time?

I have a uWSGI 2.0.12 uwsgi server running:

$ cat myt.py
import uwsgi
def application(env, start_response):
  start_response('200 OK', [('Content-Type','text/html')])
  for i in xrange(100):
    yield 'Hello, World %i<br>\n' % i
    uwsgi.async_sleep(1)
$ uwsgi --uwsgi-socket 127.0.0.1:5423 --async 99 --ugreen --module myt

So each response takes about 100 seconds to generate, 1 line of it takes 1 second.

If I change --uwsgi-socket to --http-socket, then it works just fine when I visit http://127.0.0.1:5423/ in 2 Chrome tabs: in each second, a new line appears in each tab.

However, I want to keep --uwsgi-socket, and I want to add a proxy which will convert from HTTP to uwsgi. I decided to use uwsgi --http-to as this proxy, and I've started 2 proxies:

$ uwsgi --uwsgi-socket 127.0.0.1:5423 --async 99 --ugreen --module myt
$ uwsgi --http 127.0.0.1:4114 --http-to '127.0.0.1:5423' --master
$ uwsgi --http 127.0.0.1:5115 --http-to '127.0.0.1:5423' --master

When I visit http://127.0.0.1:4114/, it works fine: it starts displaying lines in each second. However, when I visit the same link in a new tab, nothing happens for 100 seconds (until the previous requests finishes), and lines start appear only then. So either the proxy or the uwsgi server on port 5423 aren't able to handle multiple requests at the same time. To confirm that it's the proxy who is unable, I visit http://127.0.0.1:4114/ and at the same time in another tab, I visit http://127.0.0.1:5115/ , and the lines start appearing in both tabs. So 1 proxy can handle 1 response at a time.

This doesn't work in parallel either:

$ uwsgi --http 127.0.0.1:5544 --master --http-workers 9 --http-events 99 --route='^/.* uwsgi:127.0.0.1:5423,0,0' --workers 9

My question: How can I configure uwsgi --http-to so that it can handle at least 100 responses at a time?

I've tried specifying --threads 100, --processes 100, --async 100 --ugreen, --http-workers 9, --http-events 99 or specifying the --http-to flags multiple times in the same command-line, but none of these helped.

Right now I'm not interested in alternative proxy software such as NGINX or making my uwsgi --uwsgi-socket instance understand the HTTP protocol directly. I need additional command-line flags for uwsgi --http-to to make it able to handle multiple responses at the same time.

Upvotes: 1

Views: 1722

Answers (1)

GwynBleidD
GwynBleidD

Reputation: 20569

All of settings for http server are prefixed with http. List of all options is here

What you need is http-workers option, to tell uWSGI to spawn multiple workers for HTTP request processing

Upvotes: 1

Related Questions