ropensci / rzmq

R package for ZMQ
https://docs.ropensci.org/rzmq
84 stars 30 forks source link

Reusing messages in rzmq #38

Closed mschubert closed 7 years ago

mschubert commented 7 years ago

I'm developing an rzmq-based R package for distributing function calls on HPC schedulers (clustermq). For this, I need to send the same message (the function itself and constant arguments; often 100s of MB) to all workers at different times (whenever they start up - so no PUB/SUB sockets).

ZeroMQ allows to reuse messages, i.e. not copying the memory to a new buffer like sendSocket() does.

I'm posting this issue here to see if there is interest in incorporating this functionality in the rzmq package (rather than my package; and to get feedback on my approach). The way I would do this is to:

If you agree with this I will work on a PR (otherwise I'd add low-level code to my package).

armstrtw commented 7 years ago

I think it makes sense as long as we don't complicate the existing codebase too much.

you would use an external pointer for the message_t object?

mschubert commented 7 years ago

I've written a draft: https://github.com/mschubert/rzmq/commit/edcdfd6bee84f431e464631a1a5f4bc1dea922cb

Yes, this is using an external pointer to the message_t object and I've deviated a bit and written a sendMessageObject function. (Still need to check whether the gc will try to collect data_ like this, I'm not an Rcpp expert.)

mschubert commented 7 years ago

And I haven't actually figured out how to get message copy to work yet: https://stackoverflow.com/q/46181044