[erlang-questions] Synchronous communication with prim_file port
Salikhov Dinislam
Dinislam.Salikhov@REDACTED
Mon Oct 23 14:35:40 CEST 2017
Hello.
I have an erlang process that receives logs from other processes and
writes them into the file.
The logs are written to the file via file:write() which in turn boils
down to erlang:port_command/2 call followed by getting response from
driver via "receive {Port, {data, Data}} -> ... end" (see
./erts/preloaded/src/prim_file.erl, write/2 and follow the calls).
And here comes a trouble: if log rate is too high then while driver does
its job, a lot of messages are waiting in the process's message queue
and the receive has to walk through all of them to find the driver's answer.
Is there any rationale for write operation being done this way?
I'd like to propose an optimization here: if we know in advance that
standard drv_get_response/1 will be used to get driver's response, then
we can use synchronous erlang:port_control/3 instead to avoid the whole
message queue traverse.
Salikhov Dinislam
More information about the erlang-questions
mailing list