Skip to content

Commit 788c2c0

Browse files
author
Dorian Birraux
committed
Update Read message in WL initkernel.m
Update in ZeroMQ enable much faster call to SocketReadMessage. No need for a call to internal paclet function that may change without notice. WL 12 only uses Paclet exported function and system function from ZeroMQLink.
1 parent 067d412 commit 788c2c0

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

wolframclient/evaluation/kernel/initkernel.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ no matter the total size (tested with 80MB) *)
2525
{SocketWriteByteArrayFunc, SocketReadByteArrayFuncNoWait} = If[
2626
$VersionNumber < 12,
2727
{
28-
Function[{socket, ba}, ZeroMQLink`Private`ZMQWriteInternal[socket, Normal[ba]]],
29-
Function[{socketIn}, ByteArray@iRecvSingleMultipartMessageSocket[First@socketIn, 1(*Flag NOWAIT*)]]
28+
Function[{socketOut, ba}, ZeroMQLink`Private`ZMQWriteInternal[socketOut, Normal[ba]]],
29+
Function[{socketIn},
30+
Block[
31+
{data=ByteArray@iRecvSingleMultipartMessageSocket[First@socketIn, 1(*Flag NOWAIT*)]},
32+
If[Length[data] >= 3, Part[data,4;;], {}]
33+
]
34+
]
3035
}
3136
,
3237
{
3338
ZMQSocketWriteMessage,
34-
Function[socketIn_SocketObject, SocketReadMessage[socketIn, "Blocking"->False]]
39+
SocketReadMessage[#, "Blocking"->False] &
3540
}
3641

3742
];
@@ -178,9 +183,9 @@ no matter the total size (tested with 80MB) *)
178183
Block[{msg},
179184
SendAck[];
180185
While[True,
181-
msg = SocketReadByteArrayFunc[socketIn];
182-
If[Length[msg]>3,
183-
socketEventHandler[msg[[4;;]]];
186+
msg = SocketReadByteArrayFuncNoWait[socketIn];
187+
If[Length[msg]>0,
188+
socketEventHandler[msg];
184189
,
185190
SocketWaitNext[poller];
186191
]
@@ -194,9 +199,9 @@ no matter the total size (tested with 80MB) *)
194199
$Task = SessionSubmit[
195200
ScheduledTask[
196201
(
197-
msg = SocketReadByteArrayFunc[socketIn];
198-
If[Length[msg]>3,
199-
socketEventHandler[msg[[4;;]]];
202+
msg = SocketReadByteArrayFuncNoWait[socketIn];
203+
If[Length[msg]>0,
204+
socketEventHandler[msg];
200205
,
201206
SocketWaitNext[poller];
202207
]

0 commit comments

Comments
 (0)