ropensci / rzmq

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

Allow messages with long vectors #47

Closed mschubert closed 5 years ago

mschubert commented 5 years ago

rzmq currently does not allow sending long vectors as messages. Those are array-like objects whose size is bigger than the integer maximum.

.Machine$integer.max
# [1] 2147483647

Initializing a message object (or using rzmq::send.socket) works with vectors smaller than the integer size maximum,

z = rnorm(2.6e8)
object.size(z)
# 2080000048 bytes
x = rzmq::init.message(z) # works

but fails for vectors that are bigger:

z = rnorm(2.7e8)
object.size(z)
# 2160000048 bytes
x = rzmq::init.message(z)
# Error in rzmq::init.message(z) :
#   long vectors not supported yet: ../../src/include/Rinlinedfuns.h:519

The reason for this is that the serialized object's length is queried using the length function, which returns an integer and triggers an R internal assertion error.

If we instead use Rf_xlength (size_t type), the length query succeeds and we can serialize larger vectors to rzmq messages.

While this could be seen as a guard to not serialize large objects, I would argue that the limit on what makes sense is application specific and packages using rzmq should set their own limits.

jeroen commented 5 years ago

Are there any other places where we should replace int with x_len_t ?

codecov-io commented 5 years ago

Codecov Report

Merging #47 into master will not change coverage. The diff coverage is 50%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #47   +/-   ##
=======================================
  Coverage   33.72%   33.72%           
=======================================
  Files           4        4           
  Lines         685      685           
=======================================
  Hits          231      231           
  Misses        454      454
Impacted Files Coverage Δ
src/interface.cpp 28.71% <50%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 85ee8ac...60e44e6. Read the comment docs.

mschubert commented 5 years ago

Message sizes are never explicitly stored in interface.cpp, this is all handled by ZeroMQ.

So no, no need to replace anything else as far as I can tell.