janschaf's picture

Hello guys,

Not quite sure if this is the right place to ask this question, but I'll try anyway:

I am trying to implement a connection pool for my boost::asio-based client/server system. I can create a couple of connections with one socket in each connection and have all connections share the same io_service object (which already seems to help a lot in terms of performance). Still, I have to close the sockets in the connections after each request and re-connect to the endpoint to fire the next one. If I leave the socket open the first request goes through and after that I am basically sending junk over the wire.

Do you guys know how expensive this socket.connect() / socket.close() stuff is in terms of throughput and if there's a way to leave the sockets open? How would I go about implementing this. I have seen that pion::net::TCPServer contains some machinery for connection pooling but from just looking at the code I don't get the picture.

Thanks and kind regards,

Jan

Mike Dickey's picture
Why not just use Pion?

Why not just use Pion? =)

Creating and destroying connections can be quite expensive and have a significant impact both in terms of overall network usage (more control packets for the TCP) and application performance (it's a relatively expensive process).

There's nothing really special about how Pion does it. I guess you just need to make sure that the socket doesn't get destructed (shared_ptr ?) and that after you finish sending a response you pass the socket back to your request parser. If you're using HTTP, then you also have to make sure all your request/response headers conform to the standard (Connection: close/keep-alive/etc).

Submitted by Mike Dickey on Tue, 02/10/2009 - 16:39.