You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by osupit <ol...@gmail.com> on 2013/08/28 03:55:20 UTC

throttling a restlet endpoint by discarding excess requests

Hi 

I have a set of routes that looks like this:

--------------------------------------------

		<route id="getcustomer">
			<from
uri="restlet:http://{{fpRestHost}}:{{fpRestPort}}/greenfield/customer/getcustomer/{customerId}?restletMethod=GET"
/>
			<to uri="bean:customCustomerService?method=getCustomer"/>
		</route>

--------------------------------------------

In my bean "customCustomerService" I call a backend service that needs to be
protected as it falls over under load.

The requirement is that excess incoming requests need to be discarded
(returned an appropriate a HTTP status code eg  503 unavailable
immediately).  

So for example if only 10 requests can be processed concurrently, any (HTTP)
requests that come in while those ten slots are being processed  need return
to immediately to the caller.

I've looked at the Throttler EIP and the ThrottlingInflightRoutePolicy
routepolicy but these seem to just block/wait or queue excess requests to be
serviced when the protected resource is ready again.  

Is there an alternative throttling technique which allows me to discard
requests as described above?



--
View this message in context: http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: throttling a restlet endpoint by discarding excess requests

Posted by osupit <ol...@gmail.com>.
I'll check this out too - thanks.



--
View this message in context: http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738450.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: throttling a restlet endpoint by discarding excess requests

Posted by Christian Posta <ch...@gmail.com>.
Well, another thing you could look into is using a custom
ScheduledThreadPoolExecutor for the throttler. You could use a
BlockingQueue with a specific size (10 in your case), and any others that
tried to get scheduled would through an exception. Then in the throttler
config you would set 'callerRunsWhenRejected' == false so that an exception
is thrown.

Take a look here for setting your own custom queue for the
ScheduledThreadPoolExecutor:
http://stackoverflow.com/questions/13514441/scheduledthreadpoolexecutors-and-custom-queue

And take a look here for setting custom executor service for the throttler:
http://camel.apache.org/threading-model.html

HTH


On Tue, Aug 27, 2013 at 8:53 PM, osupit <ol...@gmail.com> wrote:

> Very much appreciate the quick response and insights.
>
> Unfortunately the requirement is as originally stated - I need to discard
> excess load by returning excess requests to the caller - so the Throttler
> option doesn't work for me.
>
> I'll have a poke around the Restlet docs/community and see if this has been
> come up before.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738099.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Re: throttling a restlet endpoint by discarding excess requests

Posted by Claus Ibsen <cl...@gmail.com>.
The JIRA tracker has a voting system. We use that to see which tickets
is the most popular etc.


On Mon, Sep 2, 2013 at 4:14 AM, osupit <ol...@gmail.com> wrote:
> Claus,
>
> That Throttle - Otherwise pattern would be ideal.
>
> If there is a  feature voting function somewhere I can register this with?
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738452.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: throttling a restlet endpoint by discarding excess requests

Posted by osupit <ol...@gmail.com>.
Claus,

That Throttle - Otherwise pattern would be ideal.  

If there is a  feature voting function somewhere I can register this with?   





--
View this message in context: http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738452.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: throttling a restlet endpoint by discarding excess requests

Posted by Vincent Nonnenmacher <vi...@gmail.com>.
could be much more easier/simplier to add a guard to the restlet route,
keep track of this throttling limit and return the exception from inside
Restlet.

see http://restlet.org/learn/tutorial/2.1/#part09

'guard' could be used for more needs than just securing access.




On Wed, Aug 28, 2013 at 10:38 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Yeah I assume you can configure the restlet server to have X worker
> threads. So if the load gets higher it will not accept new incoming
> requests. Or maybe a way of returning HTTP 503 as you want.
>
> Though the Camel throttler EIP could have an use-case for having a way
> of having a when .. otherwise built in so you can do
>
> from restlet
> throttle (10 / sec )
>     to backend
>     to some more stuff
>  otherwise
>     setHeader status = 503
>     setBody = empty
> end
>
>
>
>
>
> On Wed, Aug 28, 2013 at 5:53 AM, osupit <ol...@gmail.com> wrote:
> > Very much appreciate the quick response and insights.
> >
> > Unfortunately the requirement is as originally stated - I need to discard
> > excess load by returning excess requests to the caller - so the Throttler
> > option doesn't work for me.
> >
> > I'll have a poke around the Restlet docs/community and see if this has
> been
> > come up before.
> >
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738099.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: throttling a restlet endpoint by discarding excess requests

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah I assume you can configure the restlet server to have X worker
threads. So if the load gets higher it will not accept new incoming
requests. Or maybe a way of returning HTTP 503 as you want.

Though the Camel throttler EIP could have an use-case for having a way
of having a when .. otherwise built in so you can do

from restlet
throttle (10 / sec )
    to backend
    to some more stuff
 otherwise
    setHeader status = 503
    setBody = empty
end





On Wed, Aug 28, 2013 at 5:53 AM, osupit <ol...@gmail.com> wrote:
> Very much appreciate the quick response and insights.
>
> Unfortunately the requirement is as originally stated - I need to discard
> excess load by returning excess requests to the caller - so the Throttler
> option doesn't work for me.
>
> I'll have a poke around the Restlet docs/community and see if this has been
> come up before.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738099.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: throttling a restlet endpoint by discarding excess requests

Posted by osupit <ol...@gmail.com>.
Very much appreciate the quick response and insights. 

Unfortunately the requirement is as originally stated - I need to discard
excess load by returning excess requests to the caller - so the Throttler
option doesn't work for me.

I'll have a poke around the Restlet docs/community and see if this has been
come up before.  




--
View this message in context: http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089p5738099.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: throttling a restlet endpoint by discarding excess requests

Posted by Christian Posta <ch...@gmail.com>.
I guess the answer to this question depends on what Restlet framework has
built in to do that.
I just looked at the code for Restlet, and it appears to use an unbounded
ConcurrentLinkedQueue to handle incoming requests. I didn't see anything
obvious for how to throttle the requests: however, I bet it's extensible in
some way for you to write in a custom handler/throttler... though that
might be a good question for the Restlet community.

I think if you used the Throttler in Camel, it would at least slow down the
work that the Restlet threads can do (and maybe even give back 503...),
though you'd have to try it out yourself to see how much it would throttle.

You may wish to take a look at a different (jetty? or cxf-rs?) component
that depends on a container where you might be able to more easily control
that backlog of requests over the http connectors.


On Tue, Aug 27, 2013 at 6:55 PM, osupit <ol...@gmail.com> wrote:

> Hi
>
> I have a set of routes that looks like this:
>
> --------------------------------------------
>
>                 <route id="getcustomer">
>                         <from
> uri="restlet:http://
> {{fpRestHost}}:{{fpRestPort}}/greenfield/customer/getcustomer/{customerId}?restletMethod=GET"
> />
>                         <to
> uri="bean:customCustomerService?method=getCustomer"/>
>                 </route>
>
> --------------------------------------------
>
> In my bean "customCustomerService" I call a backend service that needs to
> be
> protected as it falls over under load.
>
> The requirement is that excess incoming requests need to be discarded
> (returned an appropriate a HTTP status code eg  503 unavailable
> immediately).
>
> So for example if only 10 requests can be processed concurrently, any
> (HTTP)
> requests that come in while those ten slots are being processed  need
> return
> to immediately to the caller.
>
> I've looked at the Throttler EIP and the ThrottlingInflightRoutePolicy
> routepolicy but these seem to just block/wait or queue excess requests to
> be
> serviced when the protected resource is ready again.
>
> Is there an alternative throttling technique which allows me to discard
> requests as described above?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/throttling-a-restlet-endpoint-by-discarding-excess-requests-tp5738089.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta