If your web application is complex and requires significant resources, perhaps the wrong place to implement slowban is due to a slowloris-attack problem.
Instead, you can enter slowban by proxying the application through a lightweight proxy or web server, such as lighttpd or nginx, serving from the cache and static content and using your firewall. From there, you can configure the bandwidth in your firewall, keeping the required resources relatively low, since the troll connection is mainly served by a lightweight proxy server instead of your heavy application server.
Although it has some concerns to consider on its own (namely, to include a possible insecure application for inserting ip-based rules in your firewall), iptables and the kernel are relatively lightweight.
The only thing you need to consider is the number of open connections that your system can tolerate, and when to start killing the longest open connections to make room for new ones. Definitely prepare your website to deal with low-bandwidth packages.
source share