"Trickle" attack on Minecraft servers, or Don't Use Thread-Per-Connection
corbinsimpson.com
corbinsimpson.com
If you want to DoS a server so that players can't die wool or smelt iron or hit pigs for porkchops, you should probably reevaluate what you're spending your time on.
http://paultyma.blogspot.com/2008/03/writing-java-multithrea...
I suspect it's not a threading issue in the sense he's describing. 400 threads probably shouldn't give you an OOM unless your heap size is set perilously low (in which case just about everything will give you that error).
It's also painful to then see him argue that epoll/select/NIO is the magical path to freedom. Erlang and Akka developers are trying to to cry and laugh at the same time when they see this.
If you want to create that many threads, you need to start by severely tuning down the stack size.
You are correct that the problem is not directly due to thread resource usage, but to the additional resources attached to each thread. I was able to raise the heap size, but not able to get past around 600 connections on my 32-bit x86 machine.
NIO/MINA is the right answer on Java. If you are using Erlang, well, I would suppose you would not need a Java-based solution. :3
I think my point, which admittedly is only informed by the work of some brilliant people, is that your point is not supported by data gathered on modern hardware with modern operating systems running a modern JVM. At least, not in all cases. With care and some tuning, people can get extremely good performance out of the thread-per-connection approach. Please check the document linked in the parent to this thread (http://paultyma.blogspot.com/2008/03/writing-java-multithrea...)
What's more, even the systems that are very good at this do not use something like NIO, epoll, or select (as anything other than a very buried implementation detail). Erlang, for example, doesn't restrict you to the kind of model that raw NIO does. NIO is a fine thing for what it is, and a potential building block for many things, but it's not a very compelling as a server framework. MINA is a better suggestion, but still not a universal catch all for these sorts of problems.
I'm not trying to say, "NIO is never right, tpp is never wrong." I'm just saying your categorical statement is not always correct. Making that statement is wrong, and it's misleading, and I don't think the problem you found was really due to the unavoidable overhead of the threading.
I salute you, sir.
All I have to do is create 1,000 connections per second and I'll hog all your thread resources. That's not too hard to do.
This really is just a proof of concept, after all, and not a tool which can bring down entire servers single-handedly. (At least, not anymore.)
TIME_WAIT times can be tweaked with the net.ipv4.tcp_tw_recycle and net.ipv4.tcp_tw_reuse sysctls, on Linux systems anyway.
However if doing something like behind a single software load balancer then the number of ports available will be limited to the 65k connections since the source address/port and target address(the lb) are fixed.
The why is a pretty boring story: the number exists as a check against runaway processes or big jobs (e.g. busy servers) causing an I/O overload, so the numbers are set to a "reasonable value" by default. Of course the reasonable value is usually much lower than the system can handle, and at tuned for older common hardware.
1. Convince the client to close the connection. The initiator of the close will be the one holding the TIME_WAIT socket (for ~2 minutes)
2. Send RSTs to clients that refuse to close. RST avoids creating a TIME_WAIT state. I think this is slightly more dangerous than a normal FIN close, because wandering duplicates could interfere with the next connection. From Python, you can close a TCP socket in a way that causes a RST to be sent:
# Set SO_LINGER to 1,0 which, by convention, causes a
# connection reset to be sent when close is called,
# instead of the standard FIN shutdown sequence.
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack("ii", 1, 0))
(From the patches and branch in http://twistedmatrix.com/trac/ticket/78)coughhaskellcough