1

I'm using ZeroMQ / ZMQ from Python and Java and have a question. When sending a shorter string, ZMQ uses one byte as described here (http://zguide.zeromq.org/page:all#A-Minor-Note-on-Strings)

Then what goes onto the wire is a length (one byte for shorter strings) and the string contents as individual characters.

Does anyone know how many bytes are used when sending a longer string?

user3666197
  • 1
  • 6
  • 50
  • 92
kangaroo
  • 407
  • 4
  • 19

1 Answers1

0

How many bytes are used for longer string when sending via ZMQ?

That depends on hell more things, than just on the string itself :

Your post refers to indeed historical text - the zguide pages.

While this was sure a very helpful first-read source in the early days of ZeroMQ v.2.x, today, we live with spanning many versions, from v.2.1+, 3.x, 4.x, 4.2 being so far the last stable API version in 2018-Q2.

No one can a priori guess what API-version was used on the message-sender's side, until a receiver actually sets/accepts the link-setup and .recv()-s the respective message. Relying on a C-lang based s_recv()-helper tricks in post v4.0 API is not a sure direction to follow.

Being in python, many protocol-hardwired details remain beyond your sight, yet there are byte-maps, that get filled under the hood exactly as the benevolent dictatorship, indoctrinated in the published ZeroMQ RFC/ZMTP-specifications, dictates.


If we cannot guess or know beforehand, can we ... ?

Yes, we can experiment. Best setup a controlled experiment.

Node A : The Sender
can be pythonic, being a sender:
- setup a REQ-archetype AccessNode ( details in "ZeroMQ Hierarchy in less than a five seconds" ),
- setup .setsockopt( zmq.IDENTITY, ... ) with a randomness-generated static identity,
- setup a .setsockopt( zmq.REQ_RELAXED, 1 ),
- .bind() it to a known endpoint of a transport-class of one's choice
- start an xrange()-generator controlled for L in xrange( 1, int( 1E+9 ) )-loop of .send()-s
- there load a payload .send( r"{0:}|{1:}".format( str( L ), L * r"*" ) ) - handle the respective .recv() for a REP-side "answer",
- check the error-states and adapt the time.sleep()-s / re-loops, according to the sender-side socket capacity and capability to send further payloads

Node B : The Receiver | The MitM-sniffer
ought be as low level as possible, so as to dis-assemble the RFC/ZMTP wire-line protocol, so python gets out of the candidate list. Other option may include a wire-level sniffer(s), if the selected transport-class permits ( an ipc:// or a vmci:// one will not )

  • setup a ROUTER-archetype AccessNode,
  • .connect() it to the know Node A's transport-class endpoint used,
  • start .recv()-ing messages,

If your experiment has correctly acquired / sniffed the wire-level details about the ZMTP-compliant transport sizes of the know payload compositions, your question gets repeatable, verifiable, quantitatively correct records on string-size to message-size mapping-function.

A BONUS POINT: for those indeed interested . . .

Next,
re-run the controlled white-box experiment above,
now with having the Node A: The Sender-side extended it's behaviour to also
{ randomly | deterministically } { change | alter } its own configuration
( or map both such options onto a pair of the same payload re-.send()-s )
with a
.setsockopt( zmq.REQ_CORRELATE, { on | off } )
inside its for-loop and record the observed changes in the expected outputs.

This adds a final touch to the definitive answer, as far as the API v.4.2.x permits in the 2018-Q2.

user229044
  • 232,980
  • 40
  • 330
  • 338
user3666197
  • 1
  • 6
  • 50
  • 92