What\'s a good way to survive abnormally high traffic spikes?
My thought is that at some trigger, my website should temporarily switch into a \"low bandwidth\" mode: swi
Put it in the cloud!
This probably isn't relevant for personal blogs etc but for bigger sites cloud hosting will solve this. Amazon EC2 for example, thing about this strategy is that it will cost you a ton of money.
On a smaller scale, using a CDN for all your images/static content might help a bit too, again evaluating the price is important. Amazon S3 is the CDN i hear about the most.
netstat -plant | awk '$4 ~ /:80\>/ {print}' | wc -l
This will show you all of the connections to the Apache server. You can create a cgi script that will calculate the total number of connections to the Apache service and issue a warning once it reaches a certain threshold. What to do at that point is another question.
Hopefully your server is prepared.
Never become popular.
While that will work, it's not real helpful. What you need infrastructure that can scale on very short. Something like Google Gears or Amazon's web services seems ideal for this, since even Slashdot's not going to overwhelm Google or Amazon. If you want your own server make sure your network provider isn't going to cut you off at any preset bandwidth limit. Buy enough hardware so that you're not straining just to carry your normal traffic without any slack to handle sudden spikes.
.htaccess:
RewriteEngine on
RewriteCond %{HTTP_REFERER} slashdot\.org [NC]
RewriteRule .* - [F]
About surviving you are right: switch or redirect the slashdotted link to a static html page without graphics. You might even want to put this page on an other webserver, so your original server will not take too much load.
I'd use a temporary redirection for this, and remove the redirection when the traffic wears off.
But how to detect this, this I'd like to know, too! Just counting the hits in the last few seconds might not be enough?
It's worth mentioning that clever caching and low bandwidth modes will be useless if you simply don't have enough bandwidth on your connection, so make sure the connection to your server is fat enough. Don't host it on your home DSL connection, for example.
I speak from experience of being slashdotted. It's not fun when you can't access the Internet at all because thousands of people are simultaneously trying to download photos of a computer your housemate mounted inside a George Foreman grill. No amount of firewalling will save you.