On Fri, Aug 28, 2009 at 1:17 PM, andres<[email protected]> wrote: > > Hi All, > > I'm working on a rate limiter and I keep going back and forth over > where it should go. The current iteration is very simple but in the > future I would like to have different limits based on environment > variables such as routing arguments, url arguments, or user login. > What is the best place to put the rate limiter? As far as I can tell, > the possible candidates are: > > in config/middleware.py > in lib.base.BaseController.__before__ > in lib.base.BaseController.__call__ > > Any architecture advice would be very much appreciated!
What do you mean by rate limiter? You want to deny requests if there are too many of them at once? The best place for that would be in Apache, where the C code can quickly knock off excess requests without bothering Python. Of course it would have to be based on something the Apache tools can distinguish easily, such as a URL pattern. If you want to do it in Pylons, any of the locations you mention are reasonable. The easiest place would be in '.__before__' . Middleware would be hardest because it takes some work to write middleware. But if you plan to use this code in other sites too, middleware is nicely portable. If you want to slow down the requests rather than deny them, you could insert a sleep period in .__before__ . But that would lead to more active threads, which would cause a resource problem of a different kind. -- Mike Orr <[email protected]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
