apanday
apanday

Reputation: 511

routing files with zeromq (jeromq)

I'm trying to implement a "file dispatcher" on zmq (actually jeromq, I'd rather avoid jni).

What I need is to load balance incoming files to processors:

Ideally I would like something like https://github.com/zeromq/filemq but

My idea is to use a mix of taskvent/tasksink and asyncsrv samples.

Client side:

Server side:

My first question is: does this seem like the right way to go? Anything simpler maybe?

My second question is: my current implem gets stuck on sending out the actual file data.

It's not a matter of sockets being full and dropping data, I'm starting with very small files sent in one go.

Any insight?

Thanks!

==================

Following raffian's advice I simplified my code, removing the push/pull extra socket (it does make sense now that you say it)

I'm left with the "non working" socket!

Here's my current code. It has many flaws that are out of scope for now (client ID, next chunk etc..)

For now, I'm just trying to have both guys talking to each other roughly in that sequence

Upvotes: 1

Views: 1397

Answers (1)

raffian
raffian

Reputation: 32086

On the client, you don't need PULL with DEALER. DEALER is PUSH and PULL combined, so use DEALER only, your code will be simpler.

Same goes for the server, unless you're doing something special, you don't need PUSH with ROUTER, router is bidirectional.

the server worker gets the request, and writes the response back to the inproc queue but the response never seems to go out of the server (can't see it in wireshark) and the client is stuck on the poller.poll awaiting the response.

Code Problems

In the server, you're dispatching files with args.toList.foreach before starting the proxy, this is probably why nothing is leaving the server. Start the proxy first, then use it; Also, once you call ZMQProxy(..), the code blocks indefinitely, so you'll need a separate thread to send the filepaths.

The client may have an issue with the poller. The typical pattern for polling is:

ZMQ.Poller items = new ZMQ.Poller (1);
items.register(receiver, ZMQ.Poller.POLLIN);
while (true) {

  items.poll(TIMEOUT);
  if (items.pollin(0)) {
    message = receiver.recv(0);

In the above code, 1) poll until timeout, 2) then check for messages, and if available, 3) get with receiver.recv(0). But in your code, you poll then drop into recv() without checking. You need to check if the poller has messages for that polled socket before calling recv(), otherwise, the receiver will hang if there's no messages.

Upvotes: 3

Related Questions