ExpandCollapse

+ 1 taskvent.flx

  //
  //  Task ventilator
  //  Binds PUSH socket to tcp://localhost:5557
  //  Sends batch of tasks to workers via that socket
  include "std/io/faio";
  var sys_clock = #Faio::mk_alarm_clock;
  
  open ZMQ;
  
  var context = zmq_init 1;
  
  //  Socket to send messages on
  var sender = context.mk_socket ZMQ_PUSH;
  sender.bind "tcp://*:5557";
  
  //  Socket to send start of batch message on
  var sink = context.mk_socket ZMQ_PUSH;
  sink.connect "tcp://localhost:5558";
  
  //print ("Press Enter when the workers are ready: "); fflush;
  //C_hack::ignore (readln stdin);
  //println "Sending tasks to workers...";
  
  Faio::sleep (sys_clock, 2.0); // give workers time to start up
  
  //  The first message is "0" and signals start of batch
  sink.send_string "0";
  
  
  //  Send 100 tasks
  var total_sec = 0.0;     //  Total expected cost in secs
  for var task_nbr in 0 upto 99 do
    //  Random workload from 1 to 100msecs
    var workload = (#rand % 100 + 1).double/1000.0;
    total_sec += workload;
    var s = f"%f" workload;
    sender.send_string s;
  done
  println$ f"Total expected cost: %d msec" (total_sec/1000.0).int;
  Faio::sleep (sys_clock, 1.0);              //  Give 0MQ time to deliver
  
  sink.close;
  sender.close;
  context.term;