-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtasksink2.pas
54 lines (45 loc) · 1.16 KB
/
tasksink2.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{
Task sink - design 2
Adds pub-sub flow to send kill signal to workers
@author cpicanco <[email protected]>
}
program tasksink2;
{$mode objfpc}{$H+}
uses SysUtils, zmq, zmq.helpers;
var
context, receiver, controller: Pointer;
LString : string;
task_nbr: Integer;
start_time: QWord;
begin
// Socket to receive messages on
context := zmq_ctx_new;
receiver := zmq_socket(context, ZMQ_PULL);
zmq_bind(receiver, 'tcp://*:5558');
// Socket for worker control
controller := zmq_socket(context, ZMQ_PUB);
zmq_bind(controller, 'tcp://*:5559');
// Wait for start of batch
LString := s_recv(receiver);
LString := '';
// Start our clock now
start_time := GetTickCount64;
// Process 100 confirmations
for task_nbr := 0 to 99 do
begin
LString := s_recv(receiver);
LString := '';
if (task_nbr mod 10) = 0 then
Write(':')
else
Write('.');
Flush(StdOut);
end;
WriteLn(Format('Total elapsed time: %d msec',
[GetTickCount64 - start_time]));
// Send kill signal to workers
s_send(controller, 'KILL');
zmq_close(receiver);
zmq_close(controller);
zmq_ctx_destroy(context);
end.