I took me a while to debug this problem, and I agree it could be made
clearer. Here's what I wrote in the Prudence documentation, and would be
happy if anyone could correct me if I'm wrong:
Important: The semantics of ClientResource require you to explicitly release
the response as soon as you're done using it, which will in turn release the
thread used to stream the response to you. (Though these threads might
eventually be reclaimed by a built-in garbage collection mechanism, leaving
them hanging could lead to starvation, such that further uses of
document.external will block until threads return to the pool.) It's
probably best to employ a try-finally paradigm, where the try clause
contains as little code as possible, and the finally clause releases the
response. See the example below.
var fixture
var resource = document.external('file:///myfiles/fixture.json',
'application/json')
try {
fixture = resource.get().text
}
finally {
resource.response.release()
}
On Thu, Dec 30, 2010 at 11:48 AM, David Fogel <[email protected]> wrote:
> Like Rickard, we also have started to call release() in a finally
> block for client and clientresource code, since it seemed, according
> to previous posts, that that was a necessary best practice, especially
> when using the Httpclient4 extension, where we'd seen situations where
> threads weren't getting released properly. So, it'd be great to see
> an official client-code best practice example that includes calls to
> exhaust() and release().
>
> -Dave
>
> On Thu, Dec 30, 2010 at 1:45 AM, Rickard Öberg <[email protected]>
> wrote:
> > On 2010-12-30 07.34, Jerome Louvel wrote:
> >> Hi Marc,
> >>
> >> I don't know if you still experiment issues with this, but here are a
> couple of clarifications:
> >>
> >> 1) release() has the effect of closing the underlying TCP socket,
> preventing persistent connection reuse. So it can't be recommended to
> systematically call it.
> >>
> >> 2) exhaust() does ensure a proper consumption of the entity and enable
> reuse of the connection. If you don't systematically consume the entity via
> other means (actually reading it), then calling exhaust() is the way to go.
> >
> > Is there any difference between best practices of how a client vs a
> > server should handle this? Right now we have our clients do
> > response.release() in a finally block. Does your response imply that
> > this messes up persistent connections from the clients point of view?
> >
> > /Rickard
> >
> > ------------------------------------------------------
> >
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2694744
> >
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695029
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2695067