r/java • u/ThanksMorningCoffee • Apr 14 '22
1,000,000 Concurrent Connections
https://josephmate.github.io/2022-04-14-max-connections/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 msIf your server uses
ip:sudo ip addr add 10.0.0.1/8 dev lo ping 10.0.0.13
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
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
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/Zyklonik Apr 15 '22
macOS is actually a certified UNIX - https://www.opengroup.org/openbrand/register/
3
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
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
-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.
2
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