Using socket module in production?
pablo platt
pablo.platt@REDACTED
Mon Jun 22 00:21:51 CEST 2020
Hi Frank,
You can check the pseudo code in the first post. I didn't do anything fancy.
Maybe it's possible to extend udpstress with the socket module.
https://github.com/reith/udpstress
On Mon, Jun 22, 2020 at 1:14 AM Frank Muller <frank.muller.erl@REDACTED>
wrote:
> Hi Pablo,
>
> Interesting. Can you share some code here or on GitHub?
>
> /Frank
>
> <pablo.platt@REDACTED> a écrit :
>
>> I have used the socket module for udp sockets in production. I had
>> hundreds of sockets at the same time receiving 5K packets/second and
>> sending 25K packets/second.
>> I didn't encounter errors and didn't get bug reports from users. Seems to
>> be very stable.
>> But I also didn't see any performance improvement compared to gen_udp.
>>
>> I'm using socket:recvfrom(Socket, 0, [], nowait) and
>> socket:sendto(Socket, Data, Dest, [], nowait).
>> Shouldn't I gain some performance over gen_udp?
>>
>>
>> On Fri, Jun 12, 2020 at 7:31 PM Vans S <vans_163@REDACTED> wrote:
>>
>>> We notice often using gen_tcp with sockets backend we get this warning
>>> printed:
>>>
>>> 3:24:4.923 <0.1018.0> [module: :gen_tcp_socket, socket: {:"$socket",
>>> #Reference<0.504347063.3068526593.55942>}, unknown_event: {:info,
>>> {:"$socket", {:"$socket", #Reference<0.504347063.3068526593.55942>},
>>> :select, #Reference<0.504347063.3083599875.167918>}}, state: :connected]
>>>
>>> Ignore the log format this is our custom format.
>>>
>>> Seems to be some kinda race condition in the implementation.
>>>
>>> On Friday, June 12, 2020, 09:30:07 a.m. EDT, pablo platt <
>>> pablo.platt@REDACTED> wrote:
>>>
>>>
>>> Hi Raimo,
>>>
>>> I don't mind small changes in the API if changes will be indicated in
>>> the release notes.
>>> But I worry about other breaking changes or hidden bugs.
>>> If anyone from the community is already using it in production it will
>>> be reassuring.
>>>
>>> Thank you.
>>>
>>> On Fri, Jun 12, 2020 at 4:00 PM Raimo Niskanen <
>>> raimo+erlang-questions@REDACTED> wrote:
>>>
>>> Hi Pablo!
>>>
>>> We will still make backwards incompatible changes. But we do not know of
>>> any stability issues, and welcome all that stress test the code.
>>>
>>> So your code might stop working work in a future 23.X release.
>>>
>>> / Raimo
>>>
>>>
>>> On Fri, Jun 12, 2020 at 01:48:32PM +0300, pablo platt wrote:
>>> > Hi,
>>> >
>>> > Is it safe to use the NIF socket module for UDP in production in OTP
>>> 23?
>>> > It's working in my tests but I'm not sure if it's considered unstable
>>> or if
>>> > I'm missing configuration or error handling.
>>> >
>>> > This is how I'm using it:
>>> >
>>> > open() ->
>>> > {ok, Socket} = socket:open(inet, dgram, udp),
>>> > {ok, Port} = socket:bind(Socket, any),
>>> > {Socket, Port}.
>>> >
>>> > active_once(Socket) ->
>>> > case socket:recvfrom(Socket, 0, [], nowait) of
>>> > {ok, {#{port := Port, addr := Addr}, Data}} ->
>>> > {udp, Addr, Port, Data};
>>> > {select, {select_info, _SelectTag, SelectRef}} ->
>>> > SelectRef;
>>> > {error, Reason} ->
>>> > exit(Reason),
>>> > error
>>> > end.
>>> >
>>> > send(Socket, Addr, Port, Data) ->
>>> > Dest = #{family => inet,
>>> > port => Port,
>>> > addr => Addr},
>>> > case socket:sendto(Socket, Data, Dest, [], nowait) of
>>> > ok -> ok;
>>> > {select, {select_info, _SelectTag, _SelectRef}} ->
>>> > % need to wait for {'$socket', Socket, select, SelectRef}
>>> and
>>> > resend Data?
>>> > ok
>>> > end.
>>> >
>>> > close(Socket) ->
>>> > socket:close(Socket).
>>> >
>>> > % listen for select ref
>>> > handle_info({'$socket', Socket, select, SelectRef}, _State) ->
>>> > case socket:recvfrom(Socket, 0, [], nowait) of
>>> > {ok, {#{port := Port, addr := Addr}, Data}} ->
>>> > % handle Data
>>> > ok;
>>> > {select, {select_info, _SelectTag, SelectRef}} ->
>>> > SelectRef;
>>> > {error, Reason} ->
>>> > exit(Reason),
>>> > error
>>> > end,
>>> > {noreply, State}.
>>>
>>> --
>>>
>>> / Raimo Niskanen, Erlang/OTP, Ericsson AB
>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200622/4d868052/attachment.htm>
More information about the erlang-questions
mailing list