Closed ubergarm closed 7 years ago
What's the errno from the failure?
errno is Out of memory [12]
Here is a simple test "server": dsock-server.c
Testing it with wrk
repeatably gives this output on my machine:
...
32620
32621
32622
32623
32624
32625Out of memory [12] (dsock-server.c:78)
Aborted (core dumped)
Hoping this is a "userland" error, like am I cleaning up/closing sockets/protocols or coroutines wrong?
Thanks!
After I decided to RTFM it seems that a coroutine
does not clean itself up on return and requires an explicit hclose(h)
on its handle.
I believe the same mistake is made in the libdill/perf/whisper.c. It works fine when invoked with whispers 32000
but hangs with whispers 34000
etc...
So without digging in more into the internals, it seems that if one needs more than ~2^16 simultaneous running coroutines
, one should allocate the stack manually and use go_mem()
.
Some of my confusion comes from hclose()
working across both libdill
and dsock
for both sockets/protocols/channels/coroutines. Its convenient but not immediately explicit imo.
Closing this issue and figure out a way to use a single coroutine
to garbage collect completed coroutines
stack space by signalling completion through a channel
and then hclose(handle)
... Will post here with a working example hopefully sooner than later.
Thanks!
Yep, that's right. Coroutine handle should be closed to deallocate the stack.
I think I need to fix the tutorial and some of the examples to take that into account.
Cool, the madness is slowly making sense. ;)
While this is more of a libdill
specific thing, I made a rough garbage collector demo over here at ubergarm/binks/src/garbage.c
Is there a way for a coroutine to access self.handle
or similar through the exposed API? Otherwise one could pass the coroutines handle to it after starting it through a channel... I can't think of a more elegant way to do this right now...
Cheers!
So, the problem is as follows:
Structured concurrency, i.e. systematic management of coroutine lifetimes (see here: http://libdill.org/structured-concurrency.html) is only possible if parent coroutine owns the child coroutine and kills it before finishing itself.
If coroutine is left running unattended, it's a possible coroutine leak. Also, it means that it will be forcefully shut down in middle of doing stuff when process exits.
Now, one can argue that in examples and toy applications it would be nice if a coroutine could close itself so that code is kept simple. On the other hand, do we want examples do stuff that would be considered unsafe in real-world application?
And to answer your question: No, there's no way to get handle of the current coroutine.
Hm. Maybe it would be worthwhile to have a helper object to hold a set of handles and close them when it itself if closed:
int gc = gcmake();
int cr1 = go(worker());
gcadd(gc, cr1);
int cr2 = go(worker());
gcadd(gc, cr2);
...
hclose(gc); // both cr1 and cr2 are closed here
After sleeping on it, there is probably a better way to structure this.
This toy example was trying to:
A better approach might be to:
gcadd()
and hclose(gc)
ability would make this paradigm quite clean.
That feels pretty good. I'll keep playing with it!
While playing with
libdill
anddsock
over at ubergarm/binks I've gotten stuck.The quickest way to repeat this is to run a slightly modified
step3.c
tutorial to print out how many loops its run e.g.:Then hit it with wrk like:
The output looks like:
While I know
step3.c
isn't speaking proper HTTP at all, don't understand why this is happening across my various attempts to "fake" a simple web server response.I've fiddled with the following possible solutions with no luck:
sudo sysctl -w net.ipv4.ip_local_port_range="1024 64000"
alpine:edge
anddebian:jessie
Docker baseimage containersdocker run --net=host
It may be related, but some tests occasionally fail during
make check
for bothlibdill
anddsock
.Thanks! I'm looking forward to getting enough stability to benchmark some more!
APPENDIX A
gdb
output from similar run as above indebian:jessie
containerAPPENDIX B
libdill
test log inalpine:edge
containerAPPENDIX C
dsock
test log inalpine:edge
container