Re: [Simpleweb-Support] Rejecting requests when the queue gets too deep in Simple framework
Brought to you by:
niallg
From: Niall G. <gal...@ya...> - 2017-02-28 20:36:09
|
Hi, This is dependent on what you would classify as "too busy". I would imagine an ArrayBlockingQueue with a fixed capacity could be used. There is already a Request.getRequestTime() which timestamps when the request was read from the socket. You could create transactions to feed a single threaded dispatch queue, which offers jobs to a larger thread pool fed from an ArrayBlockingQueue. Then keep the servicing thread pool within the container small. class Transaction implements Runnable { private final BlockingQueue<Runnable> ready; private final Container accept; private final Container reject; private final Request req; private final Response resp; // etc... public void run() { if(!ready.offer(() -> accept.handle(req, resp)){ reject.handle(req, resp); } }} Niall From: Mike Tovino <mik...@gm...> To: sim...@li... Sent: Tuesday, 28 February 2017, 12:22 Subject: [Simpleweb-Support] Rejecting requests when the queue gets too deep in Simple framework I’ve been utilizing Simple framework for a couple of years, and have had nothing but good experiences with the framework. I’d like to add a feature to my server where I can reject an incoming http(s) request if the the server is “too busy”. I can easily accomplish this by having the Container’s handle() method create a job queue, where it timestamps jobs as it queues them. Each time handle() is called, it could check if the head job in the queue is older than some number of seconds, and if so return a 503 error immediately from handle(). It occurs to me that there may be better way to inject this kind of logic into a Simple Framework application… so I thought I’d ask! Thanks -Mike ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Simpleweb-Support mailing list Sim...@li... https://lists.sourceforge.net/lists/listinfo/simpleweb-support |