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
coroutines memory usage #21481
Comments
I think I see what is happening here, I will report back soon. |
Hi @despiegk, I have had a look and I see what is happening. Here you are creating an endless amount of coroutines as the loop never breaks: mut t:=Test{}
mut c:=0
for {
c++
go monitor(ch2,c,mut &t)
coroutines.sleep(1000 * time.millisecond)
} And if we look at the monitor function, it also has a loop which never breaks. This means that the coroutine never finishes, and therefore its stack is never freed. fn monitor(ch chan string, counter int, mut t &Test) {
for {
//println('2 ${m}')
// coroutines.sleep(1 * time.second)
t.mycounter += 1
println('hello from monitor ${counter}')
coroutines.sleep(100 * time.millisecond)
println(t)
}
} Each time a coroutine is created space is allocated on the heap for it's stack. This stack memory is freed when the coroutine finishes. In your code there is an infinite loop, so the coroutine will never finish and it's stack memory will never get freed. Therefore an endless amount of stacks are being allocated and never freed. I hope this clears things up. |
hi @despiegk, I will have a look with your new example. 3Gb sounds too much for that EDIT: However I'm sure you can refactor the code to do what you want with less memory. For example by using less coroutines and re-using each one, something like a worker pool. Or by not having so many coroutines running at once, starting 1000 coroutines is not an issue, its the fact that those 1000 coroutines are never ending, and their memory is never cleaned up. if it was a constant flow of coroutines starting and finishing then the memory footprint would be significantly different. |
Describe the bug
see https://github.com/freeflowuniverse/crystallib/tree/development_alpine/research/coroutines/channels
v -o x -cg -enable-globals -use-coroutines run channels4.v
that seems to be an issue
Reproduction Steps
just run channels4.v
Expected Behavior
< 20 MB
Current Behavior
GB mem
Possible Solution
No response
Additional Information/Context
No response
V version
Current V version: V 0.4.5 3835308
Environment details (OS name and version, etc.)
osx
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: