Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm creating a site with a large number of small tools. One is a tool which uses a Python cgi-script that interacts with the Natural Language Toolkit (nltk), which is disk and CPU intensive. I have other services that are less intensive.

On the client side, these are rate limited with JavaScript throttling. A malicious or dumb user creating a bot could make connections directly. I would like to prevent this at as low of a level as possible, but I need it to be per-directory (the cgi scripts sit next to the index.html files).

I will also have a firewall that blocks abusive IPs making eminence requests. I would like this to return a simple 429 response with an empty JSON object as the body.

I would also like to include other rules in this, like a 30 second receive-to-transmit time, else close the connection.

How can I implement this in a lighttpd server on Debian?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

To directly answer your question, take a look at ModEvasive and Traffic Shaping from Lighttpd.

As an alternative/in addition to what you mentioned, you should be able to throttle connections per second using iptables rules.

And finally, consider using some sort of application (message) queue mechanism. That way no matter how many requests you get to your web interface/api endpoint, queue will ensure that only the desired number of parallel nltk tasks will run at the same time.

share|improve this answer
    
Thanks. ModEvasive looks good, and I've enabled it. I can't see a difference between it and Traffic Shaping. –  FakeRainBrigand Aug 11 '13 at 7:04
    
Do you know of any bidirectional queues? I need to get a response, so that I can pass it back to the client. I know I could have each write to a queue, but each must go back to the correct process. I've looked at several, and don't see any mechanism for this. Am I missing something? –  FakeRainBrigand Aug 11 '13 at 7:11
    
@FakeRainBrigand, In simplest terms you would have 2 queues: request queue and reply queue. Clients will submit to request queue and include something like "reply to" field to be used in reply queue. Workers will publish results to reply queue addressed to specific "reply to" which your client will poll for. Just google for 'python message queue' and you'll find plenty of useful results. :) –  Mxx Aug 11 '13 at 7:38
    
Okay, that makes sense. Thanks :-) –  FakeRainBrigand Aug 11 '13 at 9:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.