Uwe Hermann - webserverhttp://www.hermann-uwe.de/taxonomy/term/1477/0
enHow to run 65535 web servers on a single laptophttp://www.hermann-uwe.de/blog/how-to-run-65535-web-servers-on-a-single-laptop
<p>OK, so here's what crazy computer geeks come up with when they're bored of just sitting in the subway and staring out of the window.</p>
<p>Web servers usually run on port 80. <a href="http://en.wikipedia.org/wiki/TCP_and_UDP_port">TCP/UDP ports</a> range from 1 to 65535 (<a href="http://www.faqs.org/rfcs/rfc1700.html">port 0 is reserved</a>). You can run multiple web servers on different ports at the same time... Do you think what I think?</p>
<p>Well, first you need a web server (duh). I decided to use <a href="http://www.lighttpd.net/">lighttpd</a>, as it's said to be small and memory-efficient (which sounded pretty important given what I was trying to do). Apache would probably not be a good choice here. Mind you, I have <em>not</em> done any benchmarks at all, I'm just guessing...</p>
<pre>
$ <strong>apt-get install lighttpd</strong>
</pre><p>
Then, I wrote a little shell script containing a loop, which invoked lighttpd on port 1, 2, 3, 4, ..., 65535. That's it ;)</p>
<pre>
#!/bin/bash
TMPDIR=/tmp
CONFFILE="server.document-root = \"/var/www/\"
index-file.names = ( \"index.html\" )"
for ((i = 1; i < 300; i = i + 1)) do
echo "+++ Starting web server on port $i"
echo $CONFFILE > $TMPDIR/lighttpd.conf
echo "server.port = $i" >> $TMPDIR/lighttpd.conf
/usr/sbin/lighttpd -f $TMPDIR/lighttpd.conf
rm -f $TMPDIR/lighttpd.conf
done
</pre><p>
I'm sure this can be optimized a lot, but it's sufficient for now, and it works.</p>
<p>You can test any of the web servers by running "<code>wget http://localhost:3556/</code>" (for example). You can kill them all with <code>killall lighttpd</code>. If you already run some other daemons on some ports, you cannot start a lighttpd on the same port, so you'll end up with fewer than 65535 servers.</p>
<p>In case you try this on your hardware, make sure you have lots of RAM and lots of swap. Don't run this on production hardware. Feel free to post your experiences in the comments.</p>
http://www.hermann-uwe.de/blog/how-to-run-65535-web-servers-on-a-single-laptop#comments65535crazydaemonfunnylaptoplighttpdportscriptshellweb serverwebserverWed, 19 Aug 2009 14:36:03 +0200Uwe Hermann1499 at http://www.hermann-uwe.de