<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I am trying to implement HTTP pipelining through our module. But I am unable to figure out where the source port is allocated. The only function I saw that allocates the port is: <i>ngx_http_upstream_create_round_robin_peer</i>. However, it doesn't get called
 in the path of <i>ngx_http_run_posted_requests.</i></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<i><br>
</i></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Further, ngx_http_upstream_get_round_robin_peer allocates the peer, but every time in my case the peer pointer is pointing to the same address. However, in tcpdump I always see a different source port from which the packet is sent out indicating that a new
 socket connection is created.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Can anyone help me understand where we get the source port from the OS and create/update the peer before sending out the packets from the socket connection?</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
My purpose is to reuse the same socket connection without changing the source port and use a persistent connection.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Any help is greatly appreciated.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Devashi</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> nginx-devel <nginx-devel-bounces@nginx.org> on behalf of Maxim Dounin <mdounin@mdounin.ru><br>
<b>Sent:</b> Thursday, December 30, 2021 1:47 PM<br>
<b>To:</b> nginx-devel@nginx.org <nginx-devel@nginx.org><br>
<b>Subject:</b> Re: Using single persistent socket to send subrequests</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hello!<br>
<br>
On Thu, Dec 30, 2021 at 07:58:33AM +0000, Devashi Tandon wrote:<br>
<br>
>     upstream ext-authz-upstream-server {<br>
>                 server 172.20.10.6:9006;<br>
>                 keepalive 4;<br>
>     }<br>
<br>
[...]<br>
<br>
> However, when I create 100 simultaneous connections, they are <br>
> all sent via a different source port which means that a new <br>
> socket connection is created everytime.<br>
<br>
That's expected behaviour: the keepalive directive specifies the <br>
number of connections to cache, not the limit on the number of <br>
connections to the upstream server.  With many simultaneous <br>
requests nginx will open additional connections as needed.<br>
<br>
> How can I pipeline requests over 4 connections with keepalive <br>
> configuration set to 4?<br>
<br>
You cannot, pipelining is not supported by the proxy module.<br>
<br>
If the goal is not pipelining but to limit the number of <br>
connections to upstream servers, the "server ... max_conns=..." and <br>
the "queue" directive as available in nginx-plus might be what you <br>
want, see here:<br>
<br>
<a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_conns">http://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_conns</a><br>
<a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#queue">http://nginx.org/en/docs/http/ngx_http_upstream_module.html#queue</a><br>
<br>
Note well that such questions do not look like something related <br>
to nginx development.  A better mailing list for user-level <br>
question would be nginx@nginx.org, see here:<br>
<br>
<a href="http://nginx.org/en/support.html">http://nginx.org/en/support.html</a><br>
<br>
Hope this helps.<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx-devel mailing list<br>
nginx-devel@nginx.org<br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</div>
</span></font></div>
</body>
</html>