Strange Keepalive behavior

28 views
Skip to first unread message

Jakob Braun

unread,
Jan 17, 2024, 9:05:29 AMJan 17
to openre...@googlegroups.com

Hi,

 

I set up openresty as dynamic reverse proxy as described here:

https://openresty.org/en/dynamic-routing-based-on-redis.html

 

Here is my example config narrowed down to the problem:

server {
   listen       80;
   server_name  0.0.0.0;
   resolver 127.0.0.11;

   location /proxy {
       set $proxy "";
       rewrite_by_lua '
           ngx.var.proxy = "10.1.0.4";
       ';
       proxy_pass
https://$proxy:8080;
       proxy_redirect     off;
       proxy_set_header   Host $host;
  }


  location  /unused {
    proxy_pass         https://10.1.0.3:8080;
    proxy_redirect     off;
    proxy_set_header   Host $host;
  }
}

 

My upstream servers are contacted via https.

 

Now I’m measuring the performance of a request. With a plain nginx reverse proxy I experienced the behavior that the first request takes ~1s and the second one only 0.1s.

Now I expected the same on openresty, but here each request takes ~1s.

The strange thing is that when I change the 10.1.0.3 in the /unused location to 10.1.0.4. the following requests to /proxy are fast, even so I the route is not even used.

 

I guess this is because openresty then implicitly knows that there is an upstream and does some http keepalive.

 

Does someone understand this and can g8ive me a hint how to make also the /proxy fast?

 

Regards,

Jakob

Junlong li

unread,
Jan 17, 2024, 9:30:46 PMJan 17
to openresty-en
You can use tcpdump to check if the second request used the keepalive connection.

For the keepalive connection, I think you need to use the upstream config block. Go to https://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive for more details.

You also need to set the following two headers:

```
location /proxy {
  # Default is HTTP/1, keepalive is only enabled in HTTP/1.1
  proxy_http_version 1.1;

  # Remove the Connection header if the client sends it,
  # it could be "close" to close a keepalive connection
  proxy_set_header Connection "";
}
```

Jakob Braun

unread,
Jan 18, 2024, 5:22:46 AMJan 18
to openre...@googlegroups.com

Hello,

 

thank you for your reply.

I’ve now checked the keepalive connections. Surprisingly, none of the variants seems to use keepalives.

 

I guess the performance difference must be caused by something different. I’ve seen in the doc the option proxy_ssl_session_reuse on;

So, I had the idea that openresty maybe caches the SSL session under the hood. But setting this in the Lua handler did also not help.

 

Also setting the other options you suggested did not make a difference.

 

Regards,

Jakob

 

Von: openre...@googlegroups.com <openre...@googlegroups.com> Im Auftrag von Junlong li
Gesendet: Donnerstag, 18. Januar 2024 03:31
An: openresty-en <openre...@googlegroups.com>
Betreff: [openresty-en] Re: Strange Keepalive behavior

 

Sie erhalten nicht oft eine E-Mail von zhuizhu...@gmail.com. Erfahren Sie, warum dies wichtig ist

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openresty-en/bf177f02-8fe4-4760-acc6-4ac546b8be56n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages