r/java • • Apr 14 '22

1,000,000 Concurrent Connections

https://josephmate.github.io/2022-04-14-max-connections/
238 Upvotes

42 comments sorted by

28

u/msx Apr 14 '22

this was very interesting, thanks. i wondered about it too in the past. I'm almost there wanting to try the demo, i just fear i might break my server :D

16

u/ThanksMorningCoffee Apr 14 '22

Can't give up that sweet uptime:

uptime
 9:35  up 7 days, 12:06, 1 user, load averages: 2.38 2.44 2.56

21

u/persicsb Apr 14 '22

those are rookie numbers

13

u/msx Apr 14 '22

lol i was about to post the "rookie numbers" gif..

here's one of my server:

15:43:48 up 368 days, 21:12,  1 user,  load average: 0.00, 0.00, 0.00

3

u/ThanksMorningCoffee Apr 14 '22

My experiment killed my uptime :(

4

u/emaphis Apr 14 '22

That's OK, I've had Emacs sessions longer than that. Yes, Emacs keeps track of up time.

17

u/BestUsernameLeft Apr 14 '22

I'm sure that's just your personal server, but uptime isn't something to brag about in most places today. My first thought to this was "I wonder how many unpatched CVEs that is".

2

u/Hangman4358 Apr 18 '22

We rebuild our prod images every night to get any regular updates. If a container has been up for more than 24 hours it gets recycled just to get the latest updates.

13

u/hurxef Apr 14 '22

Lol.

9:59am up 1405 day(s), 23 min(s), 1 user, load average: 0.18, 0.20, 0.21

12

u/hippydipster Apr 14 '22

ARE YOU SURE ABOUT THAT 23 MINUTES??!?

2

u/agent154 Apr 15 '22

This feels like a my cousin Vinny reference

1

u/hippydipster Apr 16 '22

Because it is.

5

u/_INTER_ Apr 14 '22

Impressive, but I wonder what IBM Z server operators have to tell

3

u/grim-one Apr 15 '22

Monthly restarts for patching. The system stays up but the individual bits need to be taken down.

2

u/majordoob33 Apr 15 '22

I am a bit lost on the part about fixing the TCP limitations by changing the client IPs by using localhost. How does that work? How is the server able to respond without a client IP?

1

u/ThanksMorningCoffee Apr 15 '22

Sorry that was wasn't clear. I assigned an IP 10.0.0.X for each client. I configured it so that 10.0.0.X is routed to the loopback interface.

You can try it yourself.

If your server uses ifconfig:

sudo ifconfig lo0 alias 10.0.0.1/8 up
ping 10.0.0.1
ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1): 56 data bytes
64 bytes from 10.0.0.1: icmp_seq=0 ttl=64 time=0.058 ms
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.117 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.180 ms
^C
--- 10.0.0.1 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.058/0.118/0.180/0.050 ms

If your server uses ip:

sudo ip addr add 10.0.0.1/8 dev lo
ping 10.0.0.1

3

u/majordoob33 Apr 15 '22

So does that mean that instead of the socket being

0.0.0.0:80 <--> <client>:<client>

It would map it to

10.0.0.x:80 <--> <client>:<client>

How does that help?

11

u/msx Apr 14 '22

i bit the bullet and run a smaller version of the test. I did 70.000 connections with 3 interfaces, just to surpass the 65k limit. It took about 5 minutes. Cool stuff!

9

u/GavinRayDev Apr 14 '22

I appreciated the thorough analysis, great writeup!

The file limit is something I learned about the hard way previously, Alex Hultman (uWebsockets author) has a solid article on it here:

https://alexhultman.medium.com/millions-of-active-websockets-with-node-js-7dc575746a01

2

u/fzammetti Apr 14 '22

Given RELATIVELY comparable machines (well, hard to say that with certainly, but at least in terms of CPU, they're not THAT far apart) I'm surprised to see a Mac with twice the memory die ~10x sooner. I know you couldn't figure out why it was happening, it feels bizarre to me given OSX is essentially a Linux variant. I wouldn't have expected such a big delta, and I wouldn't have been surprised if it were the other way around given the memory disparity.

Just weird is all I'm sayin'.

2

u/ThanksMorningCoffee Apr 14 '22

I'm not good with Macs so it's probably user error.

2

u/fzammetti Apr 14 '22

Makes two of us :)

9

u/pellets Apr 15 '22

OSX is not a Linux variant. It has its own Darwin kernel.

1

u/Zyklonik Apr 15 '22

macOS is actually a certified UNIX - https://www.opengroup.org/openbrand/register/

4

u/larsga Apr 15 '22

Sure, but MacOS X was developed from NeXTSTEP, which in turn was based on Mach, which reused some BSD code, but was basically written from scratch.

It's a Unix, but it's not related to Linux.

2

u/Zyklonik Apr 15 '22

Nowhere in my comment did I claim that macOS is a Linux variant. On the contrary, my claim is that not only is macOS UNIX-like, it's literally certified as one.

0

u/[deleted] Apr 16 '22

[deleted]

2

u/Zyklonik Apr 16 '22

Is this subreddit filled with imbeciles? This is the second comment in this thread where someone is, ironically, conflating Linux with UNIX whilst commenting the exact opposite. Where in my comment did I mention that macOS is Linux, or that Linux is UNIX? On the contrary, my point makes it clear that not only is macOS a sort of UNIX, it is literally certified as being UNIX.

This has nothing to do with Linux.

2

u/bkail Apr 17 '22

OP said OSX is a Linux variant, and the reply corrected that it's not Linux. You replied to that person without mentioning Linux at all (and saying "actually"), so people are left to assume that either your reply is disagreeing or confusingly agreeing. From your subreplies, it seems you were agreeing and just trying to give more details, but some people assumed you were disagreeing (IMO reasonably).

Discussion via text is hard. Calling people imbeciles is not productive.

1

u/Zyklonik Apr 18 '22

You replied to that person without mentioning Linux at all (and saying "actually"), so people are left to assume that either your reply is disagreeing or confusingly agreeing.

Calling people imbeciles is not productive.

This follows directly from the quote above. Let's be fair - if someone is not even aware that Linux is not UNIX, completely fails to even read the linked resource, and then still makes a comment arguing with that information, what else can you call them?

5

u/WafflesAreDangerous Apr 15 '22

Its not a Linux variant. I think it started life as a BSD fork, but they have probably diverged significantly since.

2

u/fzammetti Apr 15 '22

Yeah, I did some reading based on another similar comment. I was misinformed.

3

u/Chloe0075 Apr 14 '22

Really nice!

3

u/ATE47 Apr 14 '22

It was interesting to read, I have no clue if it will be useful for me, but it was interesting :)

2

u/CaptainKvass Apr 14 '22

This article cleared up a lot for me, thanks!

1

u/StoneOfTriumph Apr 19 '22

That is one very interesting article! I had to share it with other dev/colleagues. Thank you!

The delta between macOS and Linux is quite interesting. Do you have any idea what this could be?

I'm running openSUSE on my thinkpad. I'm tempted to run the demo :D

1

u/simrk94 May 07 '22

Interesting read. Thanks for sharing the experiment details with us.

-4

u/verveeldeme Apr 14 '22

"For a server listening on a port, each incoming connection DOES NOT consume a port on the server."

You must be mistaken.

There may be a backlog for un-established connections, but each established connection gets it's own server port.

4

u/ThanksMorningCoffee Apr 14 '22

You're right, there is a backlog. When you create a server socket, there is a buffer for incoming connections.

There may be a backlog for un-established connections, but each established connection gets it's own server port.

The server socket only uses the port that it's listening to (443 for https for example). On the server, each accepted connection consumes a file descriptor, not a port. You can try it yourself and see use netstat to see if you can find the new port that the server opened.

6

u/OpenGLaDOS Apr 14 '22

You mean sockets (one listening socket vs. many connected ones)?

As the link says, a connection is identified by a unique combination of host + port on both sides. For example, for connections to a web server the local side will be <IP>:443 for every connection from the server's point of view, but in theory you could also have lots of clients connecting from port 60000 as long as they have all unique IPs.