| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
suppressMessages(library(pbdZMQ, quietly = TRUE)) |
| 8 |
|
| 9 |
|
| 10 |
context <- zmq.ctx.new() |
| 11 |
sender <- zmq.socket(context, ZMQ.ST()$PUSH) |
| 12 |
zmq.bind(sender, "tcp://*:5557") |
| 13 |
sink <- zmq.socket(context, ZMQ.ST()$PUSH) |
| 14 |
zmq.connect(sink, "tcp://localhost:5558") |
| 15 |
|
| 16 |
|
| 17 |
readline("Press Enter when workers are ready:") |
| 18 |
cat("Sending tasks to workers ...\n") |
| 19 |
zmq.send(sink, "0") |
| 20 |
|
| 21 |
|
| 22 |
set.seed(1234) |
| 23 |
total.msec <- 0 |
| 24 |
for(i in 1:100){ |
| 25 |
workload <- as.integer(runif(1, 1, 30)) |
| 26 |
total.msec <- total.msec + workload |
| 27 |
string <- sprintf("%d", workload) |
| 28 |
zmq.send(sender, string) |
| 29 |
Sys.sleep(runif(1, 3, 5)) |
| 30 |
} |
| 31 |
cat("Total expected cost: ", total.msec, " msec\n", sep = "") |
| 32 |
|
| 33 |
|
| 34 |
zmq.close(sink) |
| 35 |
zmq.close(sender) |
| 36 |
zmq.ctx.destroy(context) |