[fbzmq] Add support for OS X/BSD systems #19
Conversation
fbzmq/async/ZmqEventLoop.cpp
Outdated
int signalFd = signalFd_; | ||
#else | ||
createPipe(signalFds_); | ||
createPipe(callbackFds_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use kqueue in here if you guys prefer, but I think it's a overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH don't know about kqueue. Glad to learn with this change, it seems superior than epoll. Lol, side effect of being confined to linux.
This may be helpful if one wants to disable some warning that was previously added by the project itself which may cause problem on different envs. For example: Clang might warn about certain code constructions that g++ will now, this causing the code to not be compiled on OS X. In order to avoid such issues allow the caller to supress such warnings.
303f721
to
4fd7e20
Compare
any news on this one? |
Going to pull in and see how it does with our internal CI. Will report back and hopefully someone will review soon. |
@cooperlees has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@cooperlees which kind of linter do you guys for C/C++ code? |
clang formatter with some customizations, so I plan to format this after we accept it. So don't worry there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @cabelitos for a pull request to support fbzmq on MacOS & BSD. One major note about data-structure and few minor nits inline.
If you only intend to use Open/R, then you might want to reconsider the efforts of supporting fbzmq. Open/R is moving away from fbzmq and it has minimal usage.
- Only KvStore module uses it for the BACKWARD compatibility reasons to old version of Open/R. KvStore has newer interface for inter-node communication over thrift.
- OpenrEventLoop has support for fbzmq only for KvStore
So given this information an Open/R fork to drop fbzmq support for your specific use-case would suffice as well. In near future we're on verge of removing fbzmq traces from Open/R completely so you can converge to master in 1-2 months timeframe.
fbzmq/async/AsyncSignalHandler.h
Outdated
@@ -92,6 +98,10 @@ class AsyncSignalHandler { | |||
|
|||
// registered signals | |||
sigset_t registeredSignals_; | |||
|
|||
#ifdef IS_BSD | |||
std::unordered_map<int, sig_t> signalHandlers_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an array instead of map. Index of array would indicate signal-type and value would indicate signal-value. Map could get very expensive (i.e. one lookup for every message received).
signal.h has macros for MAX signal that you can leverage & initialize to 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to tweak a little bit, since SIGRTMAX is linux specific. But BSD has the same concept.
fbzmq/async/ZmqEventLoop.cpp
Outdated
int signalFd = signalFd_; | ||
#else | ||
createPipe(signalFds_); | ||
createPipe(callbackFds_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH don't know about kqueue. Glad to learn with this change, it seems superior than epoll. Lol, side effect of being confined to linux.
fbzmq/async/AsyncSignalHandler.h
Outdated
@@ -92,6 +98,10 @@ class AsyncSignalHandler { | |||
|
|||
// registered signals | |||
sigset_t registeredSignals_; | |||
|
|||
#ifdef IS_BSD | |||
std::unordered_map<int, sig_t> signalHandlers_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use array instead of map. There are limited number of signals & signal.h should have MAX signal value as well for bounded array. Most entries would go unused but performance benefit would be huge.
Map lookup on every message would cost a heavy penalty.
fbzmq/async/ZmqEventLoop.cpp
Outdated
@@ -37,27 +42,35 @@ ZmqEventLoop::ZmqEventLoop( | |||
if ((callbackFd_ = eventfd(0 /* init-value */, EFD_NONBLOCK)) < 0) { | |||
LOG(FATAL) << "ZmqEventLoop: Failed to create an eventfd."; | |||
} | |||
|
|||
int callbackFD = callbackFd_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: callbackFd for consistent naming
fbzmq/async/ZmqEventLoop.cpp
Outdated
|
||
#ifdef IS_BSD | ||
void | ||
ZmqEventLoop::createPipe(int fds[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to createPipeBsd
to be more specific that it is for Bsd only
fbzmq/async/ZmqEventLoop.cpp
Outdated
} | ||
|
||
void | ||
ZmqEventLoop::setNonBlockingFileDescriptor(int fd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use short name Fd
@cabelitos has updated the pull request. You must reimport the pull request before landing. |
@saifhhasan ty very much for the detailed review and the warning about fbzmq being deprecated on open/r. do you think that I should close this PR? anyways I sent a new version which contains all fixes that you request. Btw, yeah kqueue is great. It's our epoll on BSD world and I think that the kqueue API is easier to interact with. :] Ty very much for the awesome support guys. |
@saifhhasan has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@cabelitos I believe you can proceed with this PR as the work has already been done and there are no blockers. The main concern is that in future if someone from within FB changes fbzmq, it may break BSD as we don't have CI for BSD. I guess you might be addressing that on your end. I've pulled your latest pull request on our internal CI. And once it is green, I will trigger merge with master. BTW happy that we can help with your use-case. I discussed with a core Open/R Developer, @xiangxu1121, and he expects to have fbzmq removed from Open/R in few months timeframe (if we don't hit any roadblocks). So you can drop fbzmq dependency on your end when the changes on Open/R side lands. |
This commit adds the support for running fbzmq on OSX/bsd envs
@cabelitos has updated the pull request. You must reimport the pull request before landing. |
@cooperlees has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@saifhhasan great, I'll keep an eye on the repo in order to support it. Btw, I updated the cmake files since I got trolled by cmake with the LINUX constant not being available. I tested the new version on a linux machine and it was able to compile. (sorry for that) Thank you very much for your support and all the open/r team for the support. You guys are great! |
@cooperlees merged this pull request in f81ac82. |
Description:
This PR adds the support for using fbzmq on OS X systems which were not supported before.
I made these changes, since I was studying the openr library and I wanted to test it on my machine.
Note: This was tested on a macbook running on Apple Silicon (Apple M1)
Test Plan:
I uploaded a gif to imgur which shows the project compiling and all tests running, here's the link: https://imgur.com/gallery/YWoI6E3
(The gif is quite big, 5mb)