Nikita128
Nikita128

Reputation: 462

Are boost coroutines faster than async operations from Boost.Asio? Or in what cases coroutines can be faster?

In my case I have a server that processes plenty of sip calls (3000 simultaneously). It sends and receives SIP packets and a load of RTP packets (a packet per 20 ms).

Right now everything works asynchronously with callbacks by means of Boost.Asio.

I'm facing an optimization problem right now. Some things had been done to make it work faster (e.g. transition from dynamic allocation to pool allocation, changed the method of getting time, etc.), but acceleration was moderate.

Function profiler shows plenty of mutex_locks on top, so I think it has something to do with all these async calls. Browsing the web I found out about coroutines as an alternative to callbacks. As I understand it, they make the code look more appealing and simple, while still maintaining an asynchronous nature.

But what about its performance? Will coroutines be faster than async calls and callbacks (at least in my case)?

Here's a screenshot from profiler: Profiler output

Upvotes: 1

Views: 1399

Answers (1)

sehe
sehe

Reputation: 392833

Coroutines are NOT faster than async calls because they're the same thing for Asio.

The chief difference is the way you write your composed operations: with coros you get the implicit coro stack as "closure", otherwise you have make classes to do the same. (Depending on how you did the latter, coroutines might end up faster if they do the work more efficiently. None of that would be the bottlenecks you profiled though)

Upvotes: 2

Related Questions