Wednesday, May 11, 2011

Fun Fact of the Day

I read somewhere a few weeks ago that Erlang took up 500K for a new "thread."  I also read from the same source that programs could easily chew up massive (read: 16GB "server memory" costing ~$500 today from Newegg) amounts of memory.  Well, using back of the envelope calculations I figured out that (assuming a 1MB thread size instead of 512KB) a server receiving 1Gbps would need:

Gbit = 1024 Mbit
Mbit ~= 1000Kbit
Kbit ~= 1000 Bits

1,024,000,000 bits downstream
DIVIDED BY
8 bits per byte
EQUALS
128,000,000 MegaBytes downstream

128,000,000
DIVIDED BY
650 Bytes (roughly the size of a request packet in a DOS attack with a long string name attached to the URL)
EQUALS
196,923 (and some change) <-- This approximates the number of request packets coming in

Now we're going to assume each request creates it's own thread so that we don't have to worry about privacy or code or variables spilling over from other users...

196,923 packets incoming
MULTIPLIED BY
1024 (1 MegaByte and roughly double the minimum space required to open a new thread)
EQUALS
201,649,230 (and some change)

Of course all this assumes that our packet queue takes up 0 memory and our processor is able to handle the memory allocations, etc. and we aren't even beginning to count things like memory overhead from pointers BUT it's the best estimation I've seen.  And it indicates that I can very easily handle 1 Gbps DDoS attack on my server by writing it in extremely lightweight Erlang.

The design of my implementation of the server will GREATLY influence the amount of memory it chews up with each request and the stability of the server and where the performance bottlenecks will be.  I believe designing to survive a DDoS attack would be an excellent choice for most servers and should be attempted.