Score:0

Disabling Nginx's proxy buffering doesn't synchronize the response

pg flag

My understand on disabled Nginx's proxy buffering is that the app server will wait the client to respond instead of Nginx, so I should see many open connections, but it's not the case in my testing.

Setup:

client (10.2.0.7) <===> Nginx (10.2.0.5) <===> PythonApp (10.2.0.4, port 8000)

500 slow connections initiated by the client slowhttptest -c 500 -H -g -o my_header_stats -i 10 -r 50 -t GET -u http://pythonapp.com -x 24 -p 3

Nginx Conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events
{
    worker_connections 768;
    # multi_accept on;
}

http
{

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

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

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    # gzip on;
    upstream pythonapp
    {
        server 10.2.0.4:8000;
    }

    proxy_buffering off;
    server
    {
        listen 80;
        proxy_buffering off;
        server_name pythonapp.com;

        location /
        {
            proxy_buffering off;
            proxy_pass http://pythonapp;
        }
    }

    # include /etc/nginx/conf.d/*.conf;
    # include /etc/nginx/sites-enabled/*;
}

Can only see 1 open connection from Nginx Only 1 open connection

If I initiate slow connections from client to PythonApp server directly, I can see many open connections Setup:

client (10.2.0.7) <===> PythonApp (10.2.0.4, port 8000)

500 slow connections initiated by the client slowhttptest -c 500 -H -g -o my_header_stats -i 10 -r 50 -t GET -u http://10.2.0.4:8000 -x 24 -p 3 enter image description here

My questions are

  1. Why my app server doesn't have many open connections after Nginx reverse-proxies it?
  2. If my setting is incorrect, can you provide explicit code & config example to set up the corresponding environment, so as to show the performance or throughput difference between enabled remote buffering and disabled remote buffering?
Score:0
pg flag

Finally, I figured out how to test the throughput difference of enabled/disabled proxy buffering. I think slowtest isn't a good tool to test it. I used wrk

My new set up:

Slow client (10.2.0.7) \
                        \
                        Nginx (10.2.0.5) <===> PythonApp (10.2.0.4, port 8000)
                       /
                      /
Fast client (10.2.0.6)

You can reference this Digital Ocean guide to set up Flask app Python App:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "<h1 style='color:blue'>Hello There!</h1>"

@app.route("/big-file")
def big_file():
    return "<h1 style='color:blue'>" + "Hello There!"*1000000 + "</h1>"

if __name__ == "__main__":
    app.run(host='0.0.0.0')

Slow client:

# modprobe ifb
# ip link set dev ifb0 up
# tc qdisc add dev eth0 ingress
# tc filter add dev eth0 parent ffff: \
protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0
# tc qdisc add dev ifb0 root netem delay 750ms

Run wrk test on fast & slow client:

Slow client:

# wrk -t4 -c10 -d30  http://pythonapp.com/big-file

Fast client:

# wrk -t2 -c100 -d10 http://pythonapp.com

It's a must for slow client to access /big-file path, which will return a fairly large response. If the response is smaller than proxy_buffer_size, the connection between Nginx and proxied server will be closed very quickly, and you cannot simulate the blocking.

Connections occupied by slow clients under no proxy_buffering in Nginx & throughput of fast clients: Connections occupied by slow clients

Throughput of fast clients when no proxy buffering Test Result of fast client for no proxy buffering

If there is proxy_buffering, you shall not see connections occupied by slow clients. You can run the commands for slow clients to download slow response first, then check the connections in Nginx. No occupied connections by slow clients

Throughput of fast clients when there is proxy buffering enter image description here

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.