Hi, I'm not sure if i understood exactly what are you doing, but take a look at this: You don't need many io_service's. You just need one which runs a new thread, if a new connection to the server is made. So the io_service object is sitting around all time waiting (because you have called async_accept)- if a client connects, you can start a thread for this client and use sync network operations or you can process a bit of data and then go into another async operation, which calls the next function, if the data has been received or send. One or the other way you just need one io_service object, because shortly after a connection has been accepted, the connection is processed in another thread and the io_service object is runned again. As far as i can tell it just makes sense to run different io_service objects, if you have a multicore system and want to use all cores to accept connections. This was discussed some time ago on the mailing list and i think they wanted to take a new example into asio to show, how its done. Some exapmles for a server like i have described it are included in asio. e.g. the http server example. Did this answer you question? Kind Regards Manuel Jung pete@mu.org wrote:
I posted this under a less suitable subject line a week ago, but I got no response. I hope the above live will trigger some help.
I 've been doinking around with asio for a few weeks, and I've run into an issue I can't seem to wrap my head around.
I've been playing with some code that originally was meant to pound a server with a large amount of packets for benchmarking purposes. It uses threads to launch hundreds of threads per second.
When I replaced the old socket code with asio, and used a single io_service with run being called within each thread, I run out of file descriptors very quickly, and if I use a single io_service within each thread it's the same thing but the performance seems worse. Needless to say, this seems like a real limitation and I'm hoping I'm just being limited by my own misunderstanding, because I'm really enjoying the portability of asio.
The docs that are there seem great, but there seems to be a lot more the library can do that I am missing out on, and I think the docs seem like they are not mentioning a lot of what asio an do.
Can someone point me in the right direction for launching 1-to-N threads with a single send_to and a single receive_from within each thread that doesn't take the hit I'm seeing?
It seems to me, that it's obvious that the io-service design is the difference, because I don't get the issue at all when I use plain old sockets, and the OS thread limit is then the only limitation.
Any help would be greatly appreciated. FYI, I've done most of my experimenting on Linux and OSX.
I can send some code samples if needed, but I think the problem should be apparent if anyone else has tried to use asio with large amounts of threads.
Thanks,
Pete