-
Notifications
You must be signed in to change notification settings - Fork 53
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
Switch AsyncFD to use kEVENT on OSX / *BSD's for Asynchronous thread notification? #422
Comments
On my experiments both |
Sorry, looks like it is present in MacOS but its undocumented. |
Nice! Good to know as I wasn't sure how they compared.
Yah I think MacOS and FreeBSD make up a fair bit of the "market share" for development or servers, respectively, for BSD's.
Yah odd it's not in the man page. One stackoverflow thread said it has been available since macos 10.6. Though I suspect Apple wants most developers to use Grand Central Dispatch rather than the raw mechanisms. Looks like libevent uses it as well. The main thing I noticed with it was a bit of latency improvement. I might try and make a PR at some point, as I'll be using the asynchronous thread notification and develop on Mac. :) |
After more deep investigation i came to the conclusion not to start any development on this issue. The biggest problem here described in manual pages:
So it limits our abilities in cross-thread communication. And this brings a lot of complications to implementation. In our current async scheme we creating new Probably there is exists some method to avoid all the complexity and achieve needed results, but we already have cross-OS compatible primitives and right now i do not see how desired behavior could be emulated using |
Great work getting #406 in! It'll be handy.
It looks like Chronos is using
AsyncFD
which reminded me of a PR I'd done a while back on MacOSX for in the Nim stdlib io_selectors to use kEVENTs for async thread triggers. It might be useful for Chronos thread async as well on *BSDs.On *BSD platforms
AsyncFD
looks to usesocketpair
as well. On many systems that's normally similar to apipe
that the Nim stdlib uses for asyncfds on *BDSs.pipe
works reliably, but when you push lots of events through the timing can become a quite erratic.socketpair
probably also goes through caching & network buffers, which likepipe
, might behave oddly under load.Linux's
eventfd
implements an actual semaphore object which performs much better. On *BSD's thekqueue
mechanism has user events that are similar toeventfd
. Complete aside: Zephyr RTOS also provideseventfd
.In my case, I was using it for async thread notifications in Fidgetty and was a bit annoying. Sometimes it would take +500ms to notify when under heavy load (as in thousands of events being triggered per second). It wasn't an issue on Linux, or under lighter loads. Granted, I didn't do quantitative timing tests but the effect it pretty visible in a 120hz GUI.
If there's interest I could possibly look into it. A lot of dev's use MacOS for testing / development so it may be useful in order to make dev performance match Linux / Windows.
Background
It appears on MacOS that
pipe
(which Nim AsyncFD uses) andsocketpair
(which chronos uses) may be implemented distinctly according to this LWN article. Thesocketpair
may not exhibit the same lag / jitter issues.The text was updated successfully, but these errors were encountered: