Is it possible somehow to pass through the keepalive limitation of uwsgi? If not, what is the best way of persistent connection implementation. I'm using NGiNX + uWSGI (Python), and I want clients to have asynchronous updates from server.
uWSGI is an open source software application that "aims at developing a full stack for building hosting services". It is named after the Web Server Gateway Interface (WSGI), which was the first plugin supported by the project. uWSGI is maintained by Italian based software company unbit.
Post-buffering mode (uWSGI >= 2.0. This means that as soon as the uwsgi packet (read: the request headers) is parsed, it is forwarded to the backend/backends. Now, if your web-proxy is a streaming-one too (like apache, or the uWSGI http router), your app could be blocked for ages in case of a request with a body.
uWSGI includes an HTTP/HTTPS router/proxy/load-balancer that can forward requests to uWSGI workers. The server can be used in two ways: embedded and standalone. In embedded mode, it will automatically spawn workers and setup the communication socket.
Check the status of the uwsgi process to find out whether it was able to start: sudo systemctl status uwsgi.
Also remember to set “Connection: Keep-Alive” in your response. You can automate that using the add-header = Connection: Keep-Alive option. Since uWSGI 2.1 (master branch) you can use the http11-socket option. http11-socket may replace the add-header and http-keepalive options (but it doesn’t touch tcp stuff as so-keepalive does).
The timeout is set only between two successive read operations, not for the transmission of the whole response. If the uwsgi server does not transmit anything within this time, the connection is closed. This directive appeared in version 1.7.11. Enables or disables buffering of a client request body.
The http-socket <bind> option will make uWSGI natively speak HTTP. If your web server does not support the uwsgi protocol but is able to speak to upstream HTTP proxies, or if you are using a service like Webfaction or Heroku to host your application, you can use http-socket.
With the http-auto-gzip option, uWSGI can automatically gzip content if the uWSGI-Encoding header is set to gzip while Content-Length and Content-Encoding are not set. If you need a load balancer/proxy it can be a very good idea.
UWSGI supports keep-alive via --http-keepalive option if you receive requests via http.
/tmp$ cat app.py
def application(env, start_response):
content = b"Hello World"
start_response('200 OK', [
('Content-Type','text/html'),
('Content-Length', str(len(content))),
])
return [content]
Run with:
/tmp$ uwsgi --http=:8000 --http-keepalive -w app &> /dev/null
And we can see connect
calls via strace:
~$ strace -econnect wrk -d 10 -t 1 -c 1 http://127.0.0.1:8000
connect(3, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
Running 10s test @ http://127.0.0.1:8000
1 threads and 1 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 92.32us 56.14us 2.81ms 97.20%
Req/Sec 11.10k 389.34 11.84k 68.32%
111505 requests in 10.10s, 7.98MB read
Requests/sec: 11040.50
Transfer/sec: 808.63KB
+++ exited with 0 +++
See? Only one connection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With