Re: [xSocket-develop] Running out of connections with HttpClient?
Status: Inactive
Brought to you by:
grro
|
From: <gre...@we...> - 2008-04-14 20:25:57
|
Hi Ian,
the constructor you used -> new PostRequest(node.getAddress()+"/", new String[0]) is a convenience constructor to create a x-www-form-urlencoded POST request. By setting the body (post.setBodyDataSource(bytes, null)) you declare the encoding with null. Based on this xSocket-http creates a POST request header like
POST / HTTP/1.1
Content-Length: 3
Content-Type: application/x-www-form-urlencoded; charset=null
HOST: localhost:30002
As you see the charset is set with null. This is a bug, which I have already fixed in the trunk. I suppose this causes the strange behaviour you reported.
I'm not sure if you really want to use the content-type x-www-form-urlencoded. The PostRequest of the current trunk has been enhanced by a constructor, which accepts the parameters url, contentType and a byte array. E.g.
new PostRequest("http://localhost:30002/", "application/octet-stream", new byte[] { 65, 87, 78});
Regarding to the HttpClient you don't have to close a request or response. The HttpClient will automatically close or reuse the underlying http connection. What you should do, is to close the HttpClient. By closing the HttpClient the internal cached (open) connections will be closed.
Gregor
> -----Ursprüngliche Nachricht-----
> Von: "Ian Swett" <is...@ya...>
> Gesendet: 14.04.08 13:04:21
> An: xso...@li...
> Betreff: [xSocket-develop] Running out of connections with HttpClient?
>
> I am trying to use only the http client portion of
> xsocket at first, and it appears I'm running out of
> connections around 250, presumably because the
> existing connection isn't being closed properly.
> Eventually the first batch of requests timeout, and it
> will do another 250 posts.
>
> I can't find a close() or release() method on
> PostRequest or HttpResponse, so I'm not sure what I
> should be doing to allow HttpClient to reclaim the
> request.
>
> Here is my code for posting a byte[] as the body, it
> is very simple. In my simple performance test, I'm
> trying to call this 10000 times.
>
>
> PostRequest post = new
> PostRequest(node.getAddress()+"/", new String[0]);
> post.setBodyDataSource(bytes, null);
> HttpResponse response = client.call(post);
>
>
> I'm using the default HttpClient:
>
> client = new HttpClient();
>
>
> Thanks, Ian
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> xSocket-develop mailing list
> xSo...@li...
> https://lists.sourceforge.net/lists/listinfo/xsocket-develop
>
--
Gregor Roth
|