Rate limiting a FastCGI Perl service
<p>I have a Perl API being hosted by apache fastcgi module. It keeps 10 instances up at any given time.</p>

<p>I want to implement rate limiting to prevent rogue scripts from hammering it, or Dos attacks. </p>

<p>So far i've investigaed a few options at different points in the stack, all without the desired results.</p>

<p><strong>Iptables</strong> - I've found i can restrict requests using the firewall, however one key issue is that iptables doesn't have much to return to the client. Since thisd is an API it'd like to return either a HTTP status, or custom result.</p>

<p><strong>Apache</strong> - I tried <strong>mod_evasive</strong> as it seemed perfect for what i needed. To an extend, yes this module is very good and has the custom-ability i want. However in testing, this module is not effcient enough to protect against scripts. It is only really effective against browser initiated requests.</p>

<p><strong>Cache::FastMmap</strong> - I tried this method after reading <a href="https://stackoverflow.com/questions/501405/how-can-i-implement-server-side-rate-limiting-for-a-perl-web-service">this SO question</a>.
I fiddled about with this for a while before i realised this isn't a suitable solution for me. I'm using FastCGI which keeps instances of the perl API up. I'd need to implement FastMmap at that level as it works with parent - child processes. </p>

<p>Is there a way i can rate limit a FastCGI script on a IP basis, where i can return a suitable error &amp; the rate limiting be quick enough to prevent script based attacks? </p>