opa icon indicating copy to clipboard operation
opa copied to clipboard

Disable HTTP keep-alives for the OPA rest client

Open jasonsouza opened this issue 2 years ago • 11 comments

What is the underlying problem you're trying to solve?

Frequently pulling bundles, in certain cases, keeps a large number of connections open in OPA instances.

Describe the ideal solution

Identify under what scenario(s) are preventing such connections from closing.

Describe a "Good Enough" solution

Disabling HTTP keep-alives for the OPA rest-client can reduce the number of idle connections staying open for an extended period of time.

jasonsouza avatar Jul 12 '22 22:07 jasonsouza

cc @ashutosh-narkar @tsandall

jasonsouza avatar Jul 12 '22 22:07 jasonsouza

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

stale[bot] avatar Aug 12 '22 07:08 stale[bot]

This change would involve updating the http transport by setting DisableKeepAlives: true.

ashutosh-narkar avatar Aug 12 '22 18:08 ashutosh-narkar

Alternatively, we'd actually reuse the connection, I suppose.

srenatus avatar Aug 13 '22 12:08 srenatus

Hey @srenatus, @ashutosh-narkar

I seem to be hitting a wall when trying to see the before and after changes on this, it seems when I make a bundle and server it and then make a few requests to get the bundles, the connections go to:

➜  netstat -ant | grep :8080 | awk '{print $6}' | sort | uniq -c | sort -n
      1 LISTEN
      1 TIME_WAIT
      4 ESTABLISHED

This doesn't seem to change whether i try and get 5 bundles or 20, only the TIME_WAIT increases (I am making an assumption that the connection just automatically closes once the request is done?)

So I am not seeing much difference before and after adding:

DisableKeepAlives: true

I am not sure if I am testing this incorrectly or I am missing something in how to reproduce the issue...

Let me know your thoughts?

Thanks!

Parsifal-M avatar Aug 15 '22 22:08 Parsifal-M

If would expect to see more open connections netstat -ant | grep 8000 | grep -i established | wc -l before vs after the change where OPA keeps fetching bundles from the server.

ashutosh-narkar avatar Aug 15 '22 23:08 ashutosh-narkar

I will run a few more tests tonight and see, then report back :+1:

Edit because I did some testing, if I curl the bundles to download, or just visit the endpoint and download bundles.

➜  ~ netstat -ant | grep :8080 | grep -i established | wc -l
0
➜  ~ netstat -ant | grep :8080 | grep -i time_wait | wc -l             
24

It seems as soon as you download a bundle the connection immediately goes into TIME_WAIT not sure if this is because I am doing it on localhost or not.

Let me know your thoughts on this?

Thanks!

Parsifal-M avatar Aug 16 '22 14:08 Parsifal-M

Hey @jasonsouza,

Was wondering as you said in the initial post that "in certain cases" do you know in which case you saw this happening? Maybe I can try to replicate it this way instead :+1:

Let me know?

Thanks!

Parsifal-M avatar Aug 22 '22 07:08 Parsifal-M

It seems as soon as you download a bundle the connection immediately goes into TIME_WAIT not sure if this is because I am doing it on localhost or not.

This would be the expected behavior after the fix as the connection is now closed, correct?

ashutosh-narkar avatar Aug 22 '22 22:08 ashutosh-narkar

Hey @ashutosh-narkar,

Indeed but I also noticed the same behavior before the fix. So I am not sure if its actually needed, that was the issue I was facing.

I am not sure what results you get now if you test this? Let me know!

Thanks!

Parsifal-M avatar Aug 23 '22 12:08 Parsifal-M

one possible way might be tweaking the os' TCP configs to enable the reuse of TIME_WAIT sockets by adding the following to /etc/sysctl.conf

net.ipv4.tcp_tw_reuse = 1

If I'm not mistaken in linux, the duration is not adjustable and is defined as one minute: https://github.com/torvalds/linux/blob/master/include/net/tcp.h#L123-L124

boranx avatar Sep 13 '22 11:09 boranx

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

stale[bot] avatar Oct 13 '22 23:10 stale[bot]

Hi, I want to contribute to this issue.

aarushisoni avatar Nov 28 '22 14:11 aarushisoni

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

stale[bot] avatar Dec 28 '22 16:12 stale[bot]

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

stale[bot] avatar Apr 07 '23 09:04 stale[bot]