users@jersey.java.net

Re: [Jersey] Client: Performance: InputStream fastest possibility?

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 23 Sep 2010 09:48:04 -0700

On Thu, Sep 23, 2010 at 1:51 AM, Johannes Schneider
<mailings_at_cedarsoft.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 09/23/2010 12:00 AM, Paul Sandoz wrote:
>>
>> On Sep 18, 2010, at 10:44 AM, Tatu Saloranta wrote:
>>
>>> On Sat, Sep 18, 2010 at 10:18 AM, Johannes Schneider
>>> <mailings_at_cedarsoft.com> wrote:
>>>> -----BEGIN PGP SIGNED MESSAGE-----
>>>> Hash: SHA1
>>>>
>>>> Hi guys,
>>>>
>>>> at the moment I try to optimize some code that fetches a large JSON
>>>> document. I am using the Client provided by Jersey.
>>>>
>>>> At the moment I am calling
>>>>> resource.getEntity( InputStream.class )
>>>>
>>>> My profiler shows me, that the Jackson parser has to wait for the stream
>>>> (in HttpInputStream#read) for a long time...
>>>
>>> Sounds like maybe it is being buffered (read completely into in-memory
>>> buffer) before being handed to Jackson?
>>>
>>
>> Jersey will not buffer the response entity unless you have Jersey
>> logging enabled (using a filter).
>>
>> Are you using the Jersey client with HttpURLConnection or the Apache
>> HTTP client?
>
> I just instantiating the Client without any args. So I think it should
> use a com.sun.jersey.client.urlconnection.URLConnectionClientHandler
>
> But don't exactly know the difference between the two options you
> mentioned...

JDK's URL connection is considered to be utter crap by many. :-)
And I think it does do more buffering than alternatives. So it might
be worth checking out apache http client based client; it is
well-known and mature library, and fixes many/most issues.

On related note, I hope we can get async-http-client support in future
(thing JFA has built) -- while it is work-in-progress, it is advancing
fast and will also allow simple non-blocking operation.

-+ Tatu +-