-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add: fbr_poll and fbr_cond_wait_wto #12
base: master
Are you sure you want to change the base?
Conversation
fbr_poll to simulate non-blocking poll fbr_cond_wait_wto, fbr_cond_wait with timeout
Hello, Thank you for pull request! I'm on vacation currently with poor Internet access. Will take a look at it
|
Hey, Sorry for the late reply. I don't mind including |
I added this function to make it easier to port programs utilizing poll to libevfibers and use the co-operative threading model. Such programs are already built upon a event design. Converting them to fibers would be tedious. |
Why not convert those programs to use libev watchers directly? No conversion to fiber model required. Your approach of adding Sorry, but I decline the fiber friendly poll part of your PR, as I do not see it fit the libevfibers concept. Your In order to get the |
My target was to write something equivalent of pth's soft and hard syscall overrides. I understand the wrapper is inefficient, but my target was to port libraries like curl without involving libeio. Such libraries use poll as a mechanism to simply introduce a timeout to their socket calls and poll only a single descriptor. I usually squash my commits before merging to master. I will create a commit containing fbr_cond_wait_wto and send a pull request in some time. |
Any adequate library, including libcurl, usually provide enough support for asynchronous operations. See this example from libcurl, it integrates libcurl with libev. We successfully used this approach and created fiber level wrapper on top, which blocks single fiber until HTTP request is completed. No poll or threads involved, works with libev and works really well. Overriding e.g. read with fbr_read and making some software automagically work with fibers does not look like a robust solution for me. Best approach is to use support from the library to integrate with 3rd-party event loop. What libraries aside of libcurl are you willing to port? When you say "port", you mean create fiber-friendly wrappers? Why do you consider to not involve eio? For libcurl it might be less performant than libev integration outlined above, but it depends on the expected load. |
May be curl was a bad example. Libraries that do not support a asynchronous API like MySQL client would be a better one. Overriding is a clever hack. The authors of this paper have used pth's override feature to "port" Apache and make it asynchronous. They create 100,000 "fibers". Imagine doing that in system threads! Modifying libraries for use by libevfibers may not be practical. It will create a maintenance overhead. If I'm not mistaken, eio creates a separate thread for every sync operation. I'm trying to avoid the overhead of a system thread. |
It's still a hack, and may void one's warranty. I did not find any reference of Apache web server in this paper, they are speaking about some "700-line test web server". Fibers are still a source of nondeterminism. Imagine some library doing the following sequence of syscalls:
We can just modify it like this:
But this will lead us into trouble when two fibers will execute this code with single
The above cannot be achieved without modifying the source code manually.
This is definitely true.
libeio has a thread pool, creating a thread for every operation would be prohibitive. Typical overhead for a |
Sorry, got it mixed up. libpth developers tested against the Apache web
Anyway, I see your point. I'll remove fbr_poll and send in a pull request. |
When giving this example, I was assuming some single threaded code,
That is true either. Even two singleton writes from different fibers
Thank you! |
fbr_poll to simulate fiber friendly poll
fbr_cond_wait_wto, fbr_cond_wait with timeout