Quantcast

Http connection management

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Http connection management

Andy
Hi all,
I am using dispatch json to get a json stream from jetty, but server is not closing the connection and
after some time application is getting java.net.SocketException: Too many open files.

following trace from http commons log while initiating the connection,

 DEBUG headers - [Thread-445] [] >> Connection: Keep-Alive
 DEBUG wire - [Thread-445] [] << "HTTP/1.1 200 OK[EOL]"
 DEBUG wire - [Thread-445] [] << "Content-Type: application/json;charset=UTF-8[EOL]"
 DEBUG wire - [Thread-445] [] << "Content-Length: 3104[EOL]"
 DEBUG wire - [Thread-445] [] << "Server: Jetty(8.0.0.M1)[EOL]"
 DEBUG wire - [Thread-445] [] << "[EOL]"
 DEBUG DefaultClientConnection - [Thread-445] [] Receiving response: HTTP/1.1 200 OK
 DEBUG headers - [Thread-445] [] << HTTP/1.1 200 OK
 DEBUG headers - [Thread-445] [] << Content-Type: application/json;charset=UTF-8
 DEBUG headers - [Thread-445] [] << Content-Length: 3104
 DEBUG headers - [Thread-445] [] << Server: Jetty(8.0.0.M1)
 DEBUG ConfiguredHttpClient - [Thread-445] [] Connection can be kept alive indefinitely


1) how can i close the underlaying http connection from dispatch,
2) if server support connection reuse, how can i enable connection reuse ?

my code look like ,

    val http = new Http
    val response = http("http://localhost:8080/test" as_str)
    ...


thanks,
-Andy J
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Http connection management

n8han
Administrator
This hasn't been a problem before; it's possible that something changed in the new HttpClient backend that Dispatch uses in 0.8.x.

If you are creating new client instances for each use, could you try shutting down the connection manager when you are done with each?

http.client.getConnectionManager.shutdown()

If that works, I'd also like to know if setting a different ConnectionKeepAliveStrategy works without calling shutdown. We've never had to call shutdown explicitly through Dispatch (though this doc page I just found says you "must" [1]) and I do suspect some defaults have changed underneath it.

[1]: http://hc.apache.org/httpcomponents-client-ga/tutorial/html/httpagent.html

Nathan

On 05/20/2011 01:14 AM, Andy [via Databinder] wrote:
Hi all,
I am using dispatch json to get a json stream from jetty, but server is not closing the connection and
after some time application is getting java.net.SocketException: Too many open files.

following trace from http commons log while initiating the connection,

 DEBUG headers - [Thread-445] [] >> Connection: Keep-Alive
 DEBUG wire - [Thread-445] [] << "HTTP/1.1 200 OK[EOL]"
 DEBUG wire - [Thread-445] [] << "Content-Type: application/json;charset=UTF-8[EOL]"
 DEBUG wire - [Thread-445] [] << "Content-Length: 3104[EOL]"
 DEBUG wire - [Thread-445] [] << "Server: Jetty(8.0.0.M1)[EOL]"
 DEBUG wire - [Thread-445] [] << "[EOL]"
 DEBUG DefaultClientConnection - [Thread-445] [] Receiving response: HTTP/1.1 200 OK
 DEBUG headers - [Thread-445] [] << HTTP/1.1 200 OK
 DEBUG headers - [Thread-445] [] << Content-Type: application/json;charset=UTF-8
 DEBUG headers - [Thread-445] [] << Content-Length: 3104
 DEBUG headers - [Thread-445] [] << Server: Jetty(8.0.0.M1)
 DEBUG ConfiguredHttpClient - [Thread-445] [] Connection can be kept alive indefinitely


1) how can i close the underlaying http connection from dispatch,
2) if server support connection reuse, how can i enable connection reuse ?

my code look like ,

    val http = new Http
    val response = http("http://localhost:8080/test" as_str)
    ...


thanks,
-Andy J


If you reply to this email, your message will be added to the discussion below:
http://databinder.3617998.n2.nabble.com/Http-connection-management-tp6384786p6384786.html
To start a new topic under Databinder, email [hidden email]
To unsubscribe from Databinder, click here.

Loading...