Using single persistent socket to send subrequests

Devashi Tandon devashi.tandon at appsentinels.ai
Thu Dec 30 07:58:33 UTC 2021


Hi Maxim,

Is HTTP Pipelining supported in NGINX? How can I pipeline requests?

I have the following configuration:

location /auth {
                internal;
                proxy_connect_timeout 5000ms;
                proxy_read_timeout    5000ms;
                proxy_http_version 1.1;
                proxy_set_header Connection "keep-alive";
                proxy_pass http://ext-authz-upstream-server;
        }
    }

    upstream ext-authz-upstream-server {
                server 172.20.10.6:9006;
                keepalive 4;
    }


However, when I create 100 simultaneous connections, they are all sent via a different source port which means that a new socket connection is created everytime. How can I pipeline requests over 4 connections with keepalive configuration set to 4?

Thanks,
Devashi

________________________________
From: nginx-devel <nginx-devel-bounces at nginx.org> on behalf of Maxim Dounin <mdounin at mdounin.ru>
Sent: Wednesday, December 29, 2021 8:07 PM
To: nginx-devel at nginx.org <nginx-devel at nginx.org>
Subject: Re: Using single persistent socket to send subrequests

Hello!

On Wed, Dec 29, 2021 at 06:30:11AM +0000, Devashi Tandon wrote:

> We have a auth module in our code that sends requests to a
> server and waits for response to approve the request before
> proceeding to forward the request to a proxy server.
>
> We use the function ngx_http_post_request to post the
> subrequest.
>
> As I understand, this function adds the request to a queue which
> is then processed by ngx_http_run_posted_requests function.
>
> We observe that every single subrequest is sent over a new
> socket connection. Unfortunately, when we scale to more than
> 1000 concurrent subrequests, we start seeing socket failures.
>
> Is there a way to specify to this function, to maintain a
> persistent socket connection with the auth server and reuse the
> same socket connection for sending multiple subrequests?

In no particular order:

- Using ngx_http_post_request() directly might not be a good idea.
  Consider using ngx_http_subrequest() instead.

- For the particular task there is the auth_request module
  (https://nginx.org/en/docs/http/ngx_http_auth_request_module.html).
  It might be a good idea to use it instead of rolling your own
  module.

- Every subrequest is processed according to the configuration
  specified in the configuration file, much like any other
  request.  To use persistent connections to upstream servers you
  have to configure nginx to do so as usual, see
  http://nginx.org/r/keepalive.

Hope this helps.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx-devel mailing list
nginx-devel at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20211230/72943cef/attachment-0001.htm>


More information about the nginx-devel mailing list