[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: which is faster, creating new coroutines or reusing old coroutines #53

Open
ibogosavljevic opened this issue Mar 17, 2022 · 3 comments

Comments

@ibogosavljevic
Copy link

Hi!

I want to build a system with coroutines, but performance is my concern. My question is how to design the system: should I create a fixed number of coroutines at the beginning and keep reusing them, or can I simplify my design: create a coroutines, once it is done destroy it and create another one. I would prefer the second solution unless it is slower.

@hnes
Copy link
Owner
hnes commented Mar 17, 2022

should I create a fixed number of coroutines at the beginning and keep reusing them, or can I simplify my design: create a coroutines, once it is done destroy it and create another one

In most scenarios, there is not very much performance difference between these two choices. Strictly speaking, the former would be slightly faster than the latter because the former is more cache-friendly and some memory allocation and release operations are reduced. We can use tcmalloc to mitigate such differences.

But if the memory itself is the bottleneck of your system, then the former one is probably the better choice.

.

@ibogosavljevic
Copy link
Author

Thanks for the answer. One more question. is it possible to create a system with e.g. one main co and several slave co, such as, when aco_yield is called, the task doesn't switch to the main co, but to the next co in the ring

Currently, I have this

slave1 -> main co -> slave2 -> main co -> slave3 -> ... slave8 ->main co -> slave1

But what I want is

slave1 -> slave2 -> slave3 -> slave4 -> ... -> slave8 -> main co -> slave1

Is the second possible?

@hnes
Copy link
Owner
hnes commented Apr 2, 2022

slave1 -> main co -> slave2 -> main co -> slave3 -> ... slave8 ->main co -> slave1

Only this usage is currently supported. This is what we called asymmetric coroutine. The main co could be used as a scheduler.

slave1 -> slave2 -> slave3 -> slave4 -> ... -> slave8 -> main co -> slave1

This is what we called symmetric coroutine. And is not currently supported by libaco.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants