Matching IP address in socket module

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Matching IP address in socket module

Thomas Pircher
Hi,

I'm trying to use the new socket module, and I'm having difficulties
extracting the IP address from the socket:sockaddr_in4 record, as
returned from socket:recvfrom.
In my particular case I'm only dealing with IPv4 addresses for now.

> receive_data(Sock, State) ->
>     case socket:recvfrom(Sock, 0, nowait) of
>         {ok, {From, Data}} ->
>             NewState = handle_data(From, Data, State),
>             receive_data(Sock, NewState);
>         {select, _SelectInfo} -> {ok, State};
>         {error, Reason} -> {error, Reason}
>     end.

The problem is I don't really know how to match the From address. I would like
to match the IP address in the above statement, something like the following
pseudo-code:

>     case socket:recvfrom(Sock, 0, nowait) of
>         {ok, {#socket:sockaddr_in4{family=inet, addr=From}, Data}} ->

My (limited) understanding is that I would need to include a header file to use
records from another module, but as far as I can see, the socket module does
not define a header file.
If need be I can extract the address in the body of the case statement.

How would I get the sender address from the return value of the recvfrom function?

Thanks,
Thomas
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Mark Jones
  Thomas

While I have not used the socket module, the documentation indicates that the Source variable returned from the recvfrom function is a map not a record. So you would just need to use map matching syntax to extract the data you want.

Mark

On Thu, Oct 24, 2019 at 6:42 AM Thomas Pircher <[hidden email]> wrote:
Hi,

I'm trying to use the new socket module, and I'm having difficulties
extracting the IP address from the socket:sockaddr_in4 record, as
returned from socket:recvfrom.
In my particular case I'm only dealing with IPv4 addresses for now.

> receive_data(Sock, State) ->
>     case socket:recvfrom(Sock, 0, nowait) of
>         {ok, {From, Data}} ->
>             NewState = handle_data(From, Data, State),
>             receive_data(Sock, NewState);
>         {select, _SelectInfo} -> {ok, State};
>         {error, Reason} -> {error, Reason}
>     end.

The problem is I don't really know how to match the From address. I would like
to match the IP address in the above statement, something like the following
pseudo-code:

>     case socket:recvfrom(Sock, 0, nowait) of
>         {ok, {#socket:sockaddr_in4{family=inet, addr=From}, Data}} ->

My (limited) understanding is that I would need to include a header file to use
records from another module, but as far as I can see, the socket module does
not define a header file.
If need be I can extract the address in the body of the case statement.

How would I get the sender address from the return value of the recvfrom function?

Thanks,
Thomas
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Micael Karlberg-5
case socket:recvfrom(Sock, 0, nowait) of
       {ok, {#{family := Domain,
               port   := Port,
               addr   := Addr}, Data}} ->
       .
       .
       .


/BMK

On 2019-10-24 14:02, Mark Jones wrote:

>    Thomas
>
> While I have not used the socket module, the documentation indicates that the Source variable
> returned from the recvfrom function is a map not a record. So you would just need to use map
> matching syntax to extract the data you want.
>
> Mark
>
> On Thu, Oct 24, 2019 at 6:42 AM Thomas Pircher <[hidden email] <mailto:thp%[hidden email]>> wrote:
>
>     Hi,
>
>     I'm trying to use the new socket module, and I'm having difficulties
>     extracting the IP address from the socket:sockaddr_in4 record, as
>     returned from socket:recvfrom.
>     In my particular case I'm only dealing with IPv4 addresses for now.
>
>      > receive_data(Sock, State) ->
>      >     case socket:recvfrom(Sock, 0, nowait) of
>      >         {ok, {From, Data}} ->
>      >             NewState = handle_data(From, Data, State),
>      >             receive_data(Sock, NewState);
>      >         {select, _SelectInfo} -> {ok, State};
>      >         {error, Reason} -> {error, Reason}
>      >     end.
>
>     The problem is I don't really know how to match the From address. I would like
>     to match the IP address in the above statement, something like the following
>     pseudo-code:
>
>      >     case socket:recvfrom(Sock, 0, nowait) of
>      >         {ok, {#socket:sockaddr_in4{family=inet, addr=From}, Data}} ->
>
>     My (limited) understanding is that I would need to include a header file to use
>     records from another module, but as far as I can see, the socket module does
>     not define a header file.
>     If need be I can extract the address in the body of the case statement.
>
>     How would I get the sender address from the return value of the recvfrom function?
>
>     Thanks,
>     Thomas
>     _______________________________________________
>     erlang-questions mailing list
>     [hidden email] <mailto:[hidden email]>
>     http://erlang.org/mailman/listinfo/erlang-questions
>     <https://protect2.fireeye.com/v1/url?k=898d5b67-d5048120-898d1bfc-0cc47ad93e96-c86930fd02912db8&q=1&e=dc31b8ad-08b4-405c-b0df-ce3ba6216af4&u=http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> https://protect2.fireeye.com/v1/url?k=27955f28-7b1c856f-27951fb3-0cc47ad93e96-051349a7d0786a77&q=1&e=dc31b8ad-08b4-405c-b0df-ce3ba6216af4&u=http%3A%2F%2Ferlang.org%2Fmailman%2Flistinfo%2Ferlang-questions
>
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Thomas Pircher
Micael Karlberg wrote:
> case socket:recvfrom(Sock, 0, nowait) of
>       {ok, {#{family := Domain,
>               port   := Port,
>               addr   := Addr}, Data}} ->
>       .

Hi Micael, Mark,

thanks for your replies. The snippet above helped me getting the record
matched.

I'm quite impressed with the socket module, it seems to be pretty
complete, at least for my application.

Thanks,
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Frank Muller
Hi Thomas 

Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share some numbers. 

/Frank

> case socket:recvfrom(Sock, 0, nowait) of
>       {ok, {#{family := Domain,
>               port   := Port,
>               addr   := Addr}, Data}} ->
>       .

Hi Micael, Mark,

thanks for your replies. The snippet above helped me getting the record
matched.

I'm quite impressed with the socket module, it seems to be pretty
complete, at least for my application.

Thanks,
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Micael Karlberg-5
Hi,

Its early days still, but the goal is definitely that it should
be faster.

Here is some figures from a (time) test tool which is part of the
test suite (its basically a ping-pong case), both server and client
running on the same host (but in different VMs):

Two transports:
         gen:  gen_tcp
         sock: socket (tcp)

The socket active mode is a simulation of gen_tcp active mode
(no active = N).

The tables are the exchange from the client side.

With server side using gen (active = false):

         Transport       Active          Data
         gen             false           10192 byte/ms, 154 msgs/ms
         gen             true            10383 byte/ms, 157 msgs/ms
         gen             once            6003 byte/ms,  90  msgs/ms
         sock            false           14050 byte/ms, 212 msgs/ms
         sock            true            14772 byte/ms, 223 msgs/ms
         sock            once            14050 byte/ms, 210 msgs/ms


With server side using gen (active = true):

         Transport       Active          Data
         gen             false           9447 byte/ms,  143 msgs/ms
         gen             true            22345 byte/ms, 338 msgs/ms
         gen             once            5532 byte/ms,  83  msgs/ms
         sock            false           15316 byte/ms, 232 msgs/ms
         sock            true            23693 byte/ms, 358 msgs/ms
         sock            once            22068 byte/ms, 334 msgs/ms


With server side using sock (active = false, async = true):

         Transport       Active          Data
         gen             false           11260 byte/ms, 170 msgs/ms
         gen             true            22273 byte/ms, 337 msgs/ms
         gen             once            7703 byte/ms,  116 msgs/ms
         sock            false           15211 byte/ms, 230 msgs/ms
         sock            true            24778 byte/ms, 375 msgs/ms
         sock            once            23086 byte/ms, 349 msgs/ms


With server side using sock (active = true, async = true):

         Transport       Active          Data
         gen             false           11351 byte/ms, 171 msgs/ms
         gen             true            22469 byte/ms, 340 msgs/ms
         gen             once            7407 byte/ms,  112 msgs/ms
         sock            false           15484 byte/ms, 234 msgs/ms
         sock            true            24885 byte/ms, 377 msgs/ms
         sock            once            23570 byte/ms, 357 msgs/ms


There is of course a bit of overhead since the socket transport
is trying to emulate (part of) gen_tcp.

This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
that effects the relative performance).
Run with a snapshot from the maint branch.

This is obviously not a real use case, but it can be a guideline.
Also no UDP test (at the moment).

/BMK

On 2019-10-24 18:48, Frank Muller wrote:

> Hi Thomas
>
> Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share some
> numbers.
>
> /Frank
>
>      > case socket:recvfrom(Sock, 0, nowait) of
>      >       {ok, {#{family := Domain,
>      >               port   := Port,
>      >               addr   := Addr}, Data}} ->
>      >       .
>
>     Hi Micael, Mark,
>
>     thanks for your replies. The snippet above helped me getting the record
>     matched.
>
>     I'm quite impressed with the socket module, it seems to be pretty
>     complete, at least for my application.
>
>     Thanks,
>     Thomas
>
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Frank Muller
Awesome, thanks!

Le ven. 25 oct. 2019 à 12:39, Micael Karlberg <[hidden email]> a écrit :
Hi,

Its early days still, but the goal is definitely that it should
be faster.

Here is some figures from a (time) test tool which is part of the
test suite (its basically a ping-pong case), both server and client
running on the same host (but in different VMs):

Two transports:
         gen:  gen_tcp
         sock: socket (tcp)

The socket active mode is a simulation of gen_tcp active mode
(no active = N).

The tables are the exchange from the client side.

With server side using gen (active = false):

         Transport       Active          Data
         gen             false           10192 byte/ms, 154 msgs/ms
         gen             true            10383 byte/ms, 157 msgs/ms
         gen             once            6003 byte/ms,  90  msgs/ms
         sock            false           14050 byte/ms, 212 msgs/ms
         sock            true            14772 byte/ms, 223 msgs/ms
         sock            once            14050 byte/ms, 210 msgs/ms


With server side using gen (active = true):

         Transport       Active          Data
         gen             false           9447 byte/ms,  143 msgs/ms
         gen             true            22345 byte/ms, 338 msgs/ms
         gen             once            5532 byte/ms,  83  msgs/ms
         sock            false           15316 byte/ms, 232 msgs/ms
         sock            true            23693 byte/ms, 358 msgs/ms
         sock            once            22068 byte/ms, 334 msgs/ms


With server side using sock (active = false, async = true):

         Transport       Active          Data
         gen             false           11260 byte/ms, 170 msgs/ms
         gen             true            22273 byte/ms, 337 msgs/ms
         gen             once            7703 byte/ms,  116 msgs/ms
         sock            false           15211 byte/ms, 230 msgs/ms
         sock            true            24778 byte/ms, 375 msgs/ms
         sock            once            23086 byte/ms, 349 msgs/ms


With server side using sock (active = true, async = true):

         Transport       Active          Data
         gen             false           11351 byte/ms, 171 msgs/ms
         gen             true            22469 byte/ms, 340 msgs/ms
         gen             once            7407 byte/ms,  112 msgs/ms
         sock            false           15484 byte/ms, 234 msgs/ms
         sock            true            24885 byte/ms, 377 msgs/ms
         sock            once            23570 byte/ms, 357 msgs/ms


There is of course a bit of overhead since the socket transport
is trying to emulate (part of) gen_tcp.

This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
that effects the relative performance).
Run with a snapshot from the maint branch.

This is obviously not a real use case, but it can be a guideline.
Also no UDP test (at the moment).

/BMK

On 2019-10-24 18:48, Frank Muller wrote:
> Hi Thomas
>
> Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share some
> numbers.
>
> /Frank
>
>      > case socket:recvfrom(Sock, 0, nowait) of
>      >       {ok, {#{family := Domain,
>      >               port   := Port,
>      >               addr   := Addr}, Data}} ->
>      >       .
>
>     Hi Micael, Mark,
>
>     thanks for your replies. The snippet above helped me getting the record
>     matched.
>
>     I'm quite impressed with the socket module, it seems to be pretty
>     complete, at least for my application.
>
>     Thanks,
>     Thomas
>
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Thomas Pircher
In reply to this post by Thomas Pircher
Thomas Pircher wrote:
> I'm quite impressed with the socket module, it seems to be pretty
> complete, at least for my application.

Hi, I'm having another problem with the socket module, I'm hoping
someone could help me understanding what is going on here.

I'm attempting to send a packet from an arbitrary IP address. My
understanding is that this can be done using the pktinfo structure on a
Linux system. There is no direct support for this in the cmsghdr_send()
type, so I thought I can use the #{level := ip, type := integer(), …}
construct instead. (I know this is non-portable.)

Using the following code snippet I can get packets out of the system,
but the pktinfo data seems to be ignored; the output interface is
selected by the routing table (and not by the IfIndex variable) and the
source IP address is not the one I set in the control header.

-define(IP_PKTINFO, 8).
send(DstIp, IfIndex, Data) ->
    {ok, Socket} = socket:open(inet, dgram),
    DstAddr = #{family => inet, addr => DstIp, port => 42001},
    Ctrl = #{level => udp, type => ?IP_PKTINFO, data => <<IfIndex:32,  10, 42, 1, 1,  10, 42, 1, 1>>},
    MsgHdr = #{addr => DstAddr, ctrl => [Ctrl], flags => [], iov => [Data]},
    Res = socket:sendmsg(Socket, MsgHdr),
    io:format("Sent message ~p~n", [Res]).

Is there something I'm doing wrong?

Thanks,
Thomas
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Loïc Hoguin-3
In reply to this post by Micael Karlberg-5
Hello,

I would like to do a similar experiment with RabbitMQ. Would you mind
sharing the code that makes 'socket' work similar to 'gen_tcp'? That may
give me a head start, even if the code is not complete.

Thanks,

On 25/10/2019 12:39, Micael Karlberg wrote:

> Hi,
>
> Its early days still, but the goal is definitely that it should
> be faster.
>
> Here is some figures from a (time) test tool which is part of the
> test suite (its basically a ping-pong case), both server and client
> running on the same host (but in different VMs):
>
> Two transports:
>          gen:  gen_tcp
>          sock: socket (tcp)
>
> The socket active mode is a simulation of gen_tcp active mode
> (no active = N).
>
> The tables are the exchange from the client side.
>
> With server side using gen (active = false):
>
>          Transport       Active          Data
>          gen             false           10192 byte/ms, 154 msgs/ms
>          gen             true            10383 byte/ms, 157 msgs/ms
>          gen             once            6003 byte/ms,  90  msgs/ms
>          sock            false           14050 byte/ms, 212 msgs/ms
>          sock            true            14772 byte/ms, 223 msgs/ms
>          sock            once            14050 byte/ms, 210 msgs/ms
>
>
> With server side using gen (active = true):
>
>          Transport       Active          Data
>          gen             false           9447 byte/ms,  143 msgs/ms
>          gen             true            22345 byte/ms, 338 msgs/ms
>          gen             once            5532 byte/ms,  83  msgs/ms
>          sock            false           15316 byte/ms, 232 msgs/ms
>          sock            true            23693 byte/ms, 358 msgs/ms
>          sock            once            22068 byte/ms, 334 msgs/ms
>
>
> With server side using sock (active = false, async = true):
>
>          Transport       Active          Data
>          gen             false           11260 byte/ms, 170 msgs/ms
>          gen             true            22273 byte/ms, 337 msgs/ms
>          gen             once            7703 byte/ms,  116 msgs/ms
>          sock            false           15211 byte/ms, 230 msgs/ms
>          sock            true            24778 byte/ms, 375 msgs/ms
>          sock            once            23086 byte/ms, 349 msgs/ms
>
>
> With server side using sock (active = true, async = true):
>
>          Transport       Active          Data
>          gen             false           11351 byte/ms, 171 msgs/ms
>          gen             true            22469 byte/ms, 340 msgs/ms
>          gen             once            7407 byte/ms,  112 msgs/ms
>          sock            false           15484 byte/ms, 234 msgs/ms
>          sock            true            24885 byte/ms, 377 msgs/ms
>          sock            once            23570 byte/ms, 357 msgs/ms
>
>
> There is of course a bit of overhead since the socket transport
> is trying to emulate (part of) gen_tcp.
>
> This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
> that effects the relative performance).
> Run with a snapshot from the maint branch.
>
> This is obviously not a real use case, but it can be a guideline.
> Also no UDP test (at the moment).
>
> /BMK
>
> On 2019-10-24 18:48, Frank Muller wrote:
>> Hi Thomas
>>
>> Is the socket module faster than gen_tcp/gen_udp in your case? If yes,
>> can you please share some numbers.
>>
>> /Frank
>>
>>      > case socket:recvfrom(Sock, 0, nowait) of
>>      >       {ok, {#{family := Domain,
>>      >               port   := Port,
>>      >               addr   := Addr}, Data}} ->
>>      >       .
>>
>>     Hi Micael, Mark,
>>
>>     thanks for your replies. The snippet above helped me getting the
>> record
>>     matched.
>>
>>     I'm quite impressed with the socket module, it seems to be pretty
>>     complete, at least for my application.
>>
>>     Thanks,
>>     Thomas
>>

--
Loïc Hoguin
https://ninenines.eu
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Micael Karlberg-5
Hi,

Its not a secret :) You will find it in the emulator test catalog.
The only problem is that it was never intended for public "consumption"
and is therefor not documented:

        socket_test_ttest_tcp_socket.erl (uses socket.erl)
        socket_test_ttest_tcp_gen.erl    (uses gen_tcp.erl)

The idea here is that they should have an "identical" interface (so
the users should work with both transports).
Obviously the "socket" is different (a gen_tcp socket is a port and
a socket socket is a term()).

The other socket_test_ttest_tcp* modules "can" be used to see how to
use these...

Also, there is work on making gen_tcp work with the new socket module.
This is ongoing. There is a lot of special options that gen_tcp/inet
manages (packaging for instance).

Regards,
        /BMK

On 2019-10-29 10:54, Loïc Hoguin wrote:

> Hello,
>
> I would like to do a similar experiment with RabbitMQ. Would you mind sharing the code that makes
> 'socket' work similar to 'gen_tcp'? That may give me a head start, even if the code is not complete.
>
> Thanks,
>
> On 25/10/2019 12:39, Micael Karlberg wrote:
>> Hi,
>>
>> Its early days still, but the goal is definitely that it should
>> be faster.
>>
>> Here is some figures from a (time) test tool which is part of the
>> test suite (its basically a ping-pong case), both server and client
>> running on the same host (but in different VMs):
>>
>> Two transports:
>>          gen:  gen_tcp
>>          sock: socket (tcp)
>>
>> The socket active mode is a simulation of gen_tcp active mode
>> (no active = N).
>>
>> The tables are the exchange from the client side.
>>
>> With server side using gen (active = false):
>>
>>          Transport       Active          Data
>>          gen             false           10192 byte/ms, 154 msgs/ms
>>          gen             true            10383 byte/ms, 157 msgs/ms
>>          gen             once            6003 byte/ms,  90  msgs/ms
>>          sock            false           14050 byte/ms, 212 msgs/ms
>>          sock            true            14772 byte/ms, 223 msgs/ms
>>          sock            once            14050 byte/ms, 210 msgs/ms
>>
>>
>> With server side using gen (active = true):
>>
>>          Transport       Active          Data
>>          gen             false           9447 byte/ms,  143 msgs/ms
>>          gen             true            22345 byte/ms, 338 msgs/ms
>>          gen             once            5532 byte/ms,  83  msgs/ms
>>          sock            false           15316 byte/ms, 232 msgs/ms
>>          sock            true            23693 byte/ms, 358 msgs/ms
>>          sock            once            22068 byte/ms, 334 msgs/ms
>>
>>
>> With server side using sock (active = false, async = true):
>>
>>          Transport       Active          Data
>>          gen             false           11260 byte/ms, 170 msgs/ms
>>          gen             true            22273 byte/ms, 337 msgs/ms
>>          gen             once            7703 byte/ms,  116 msgs/ms
>>          sock            false           15211 byte/ms, 230 msgs/ms
>>          sock            true            24778 byte/ms, 375 msgs/ms
>>          sock            once            23086 byte/ms, 349 msgs/ms
>>
>>
>> With server side using sock (active = true, async = true):
>>
>>          Transport       Active          Data
>>          gen             false           11351 byte/ms, 171 msgs/ms
>>          gen             true            22469 byte/ms, 340 msgs/ms
>>          gen             once            7407 byte/ms,  112 msgs/ms
>>          sock            false           15484 byte/ms, 234 msgs/ms
>>          sock            true            24885 byte/ms, 377 msgs/ms
>>          sock            once            23570 byte/ms, 357 msgs/ms
>>
>>
>> There is of course a bit of overhead since the socket transport
>> is trying to emulate (part of) gen_tcp.
>>
>> This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
>> that effects the relative performance).
>> Run with a snapshot from the maint branch.
>>
>> This is obviously not a real use case, but it can be a guideline.
>> Also no UDP test (at the moment).
>>
>> /BMK
>>
>> On 2019-10-24 18:48, Frank Muller wrote:
>>> Hi Thomas
>>>
>>> Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share some
>>> numbers.
>>>
>>> /Frank
>>>
>>>      > case socket:recvfrom(Sock, 0, nowait) of
>>>      >       {ok, {#{family := Domain,
>>>      >               port   := Port,
>>>      >               addr   := Addr}, Data}} ->
>>>      >       .
>>>
>>>     Hi Micael, Mark,
>>>
>>>     thanks for your replies. The snippet above helped me getting the record
>>>     matched.
>>>
>>>     I'm quite impressed with the socket module, it seems to be pretty
>>>     complete, at least for my application.
>>>
>>>     Thanks,
>>>     Thomas
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

pablo platt-3
Micael, are there similar tests for udp?

On Tue, Oct 29, 2019 at 12:12 PM Micael Karlberg <[hidden email]> wrote:
Hi,

Its not a secret :) You will find it in the emulator test catalog.
The only problem is that it was never intended for public "consumption"
and is therefor not documented:

        socket_test_ttest_tcp_socket.erl (uses socket.erl)
        socket_test_ttest_tcp_gen.erl    (uses gen_tcp.erl)

The idea here is that they should have an "identical" interface (so
the users should work with both transports).
Obviously the "socket" is different (a gen_tcp socket is a port and
a socket socket is a term()).

The other socket_test_ttest_tcp* modules "can" be used to see how to
use these...

Also, there is work on making gen_tcp work with the new socket module.
This is ongoing. There is a lot of special options that gen_tcp/inet
manages (packaging for instance).

Regards,
        /BMK

On 2019-10-29 10:54, Loïc Hoguin wrote:
> Hello,
>
> I would like to do a similar experiment with RabbitMQ. Would you mind sharing the code that makes
> 'socket' work similar to 'gen_tcp'? That may give me a head start, even if the code is not complete.
>
> Thanks,
>
> On 25/10/2019 12:39, Micael Karlberg wrote:
>> Hi,
>>
>> Its early days still, but the goal is definitely that it should
>> be faster.
>>
>> Here is some figures from a (time) test tool which is part of the
>> test suite (its basically a ping-pong case), both server and client
>> running on the same host (but in different VMs):
>>
>> Two transports:
>>          gen:  gen_tcp
>>          sock: socket (tcp)
>>
>> The socket active mode is a simulation of gen_tcp active mode
>> (no active = N).
>>
>> The tables are the exchange from the client side.
>>
>> With server side using gen (active = false):
>>
>>          Transport       Active          Data
>>          gen             false           10192 byte/ms, 154 msgs/ms
>>          gen             true            10383 byte/ms, 157 msgs/ms
>>          gen             once            6003 byte/ms,  90  msgs/ms
>>          sock            false           14050 byte/ms, 212 msgs/ms
>>          sock            true            14772 byte/ms, 223 msgs/ms
>>          sock            once            14050 byte/ms, 210 msgs/ms
>>
>>
>> With server side using gen (active = true):
>>
>>          Transport       Active          Data
>>          gen             false           9447 byte/ms,  143 msgs/ms
>>          gen             true            22345 byte/ms, 338 msgs/ms
>>          gen             once            5532 byte/ms,  83  msgs/ms
>>          sock            false           15316 byte/ms, 232 msgs/ms
>>          sock            true            23693 byte/ms, 358 msgs/ms
>>          sock            once            22068 byte/ms, 334 msgs/ms
>>
>>
>> With server side using sock (active = false, async = true):
>>
>>          Transport       Active          Data
>>          gen             false           11260 byte/ms, 170 msgs/ms
>>          gen             true            22273 byte/ms, 337 msgs/ms
>>          gen             once            7703 byte/ms,  116 msgs/ms
>>          sock            false           15211 byte/ms, 230 msgs/ms
>>          sock            true            24778 byte/ms, 375 msgs/ms
>>          sock            once            23086 byte/ms, 349 msgs/ms
>>
>>
>> With server side using sock (active = true, async = true):
>>
>>          Transport       Active          Data
>>          gen             false           11351 byte/ms, 171 msgs/ms
>>          gen             true            22469 byte/ms, 340 msgs/ms
>>          gen             once            7407 byte/ms,  112 msgs/ms
>>          sock            false           15484 byte/ms, 234 msgs/ms
>>          sock            true            24885 byte/ms, 377 msgs/ms
>>          sock            once            23570 byte/ms, 357 msgs/ms
>>
>>
>> There is of course a bit of overhead since the socket transport
>> is trying to emulate (part of) gen_tcp.
>>
>> This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
>> that effects the relative performance).
>> Run with a snapshot from the maint branch.
>>
>> This is obviously not a real use case, but it can be a guideline.
>> Also no UDP test (at the moment).
>>
>> /BMK
>>
>> On 2019-10-24 18:48, Frank Muller wrote:
>>> Hi Thomas
>>>
>>> Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share some
>>> numbers.
>>>
>>> /Frank
>>>
>>>      > case socket:recvfrom(Sock, 0, nowait) of
>>>      >       {ok, {#{family := Domain,
>>>      >               port   := Port,
>>>      >               addr   := Addr}, Data}} ->
>>>      >       .
>>>
>>>     Hi Micael, Mark,
>>>
>>>     thanks for your replies. The snippet above helped me getting the record
>>>     matched.
>>>
>>>     I'm quite impressed with the socket module, it seems to be pretty
>>>     complete, at least for my application.
>>>
>>>     Thanks,
>>>     Thomas
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

Micael Karlberg-5
No, its on the todo list, there is actually a ticket for this.
I would be good for completeness, if nothing else.

/BMK

On 2019-10-29 11:33, pablo platt wrote:

> Micael, are there similar tests for udp?
>
> On Tue, Oct 29, 2019 at 12:12 PM Micael Karlberg <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi,
>
>     Its not a secret :) You will find it in the emulator test catalog.
>     The only problem is that it was never intended for public "consumption"
>     and is therefor not documented:
>
>              socket_test_ttest_tcp_socket.erl (uses socket.erl)
>              socket_test_ttest_tcp_gen.erl    (uses gen_tcp.erl)
>
>     The idea here is that they should have an "identical" interface (so
>     the users should work with both transports).
>     Obviously the "socket" is different (a gen_tcp socket is a port and
>     a socket socket is a term()).
>
>     The other socket_test_ttest_tcp* modules "can" be used to see how to
>     use these...
>
>     Also, there is work on making gen_tcp work with the new socket module.
>     This is ongoing. There is a lot of special options that gen_tcp/inet
>     manages (packaging for instance).
>
>     Regards,
>              /BMK
>
>     On 2019-10-29 10:54, Loïc Hoguin wrote:
>      > Hello,
>      >
>      > I would like to do a similar experiment with RabbitMQ. Would you mind sharing the code that
>     makes
>      > 'socket' work similar to 'gen_tcp'? That may give me a head start, even if the code is not
>     complete.
>      >
>      > Thanks,
>      >
>      > On 25/10/2019 12:39, Micael Karlberg wrote:
>      >> Hi,
>      >>
>      >> Its early days still, but the goal is definitely that it should
>      >> be faster.
>      >>
>      >> Here is some figures from a (time) test tool which is part of the
>      >> test suite (its basically a ping-pong case), both server and client
>      >> running on the same host (but in different VMs):
>      >>
>      >> Two transports:
>      >>          gen:  gen_tcp
>      >>          sock: socket (tcp)
>      >>
>      >> The socket active mode is a simulation of gen_tcp active mode
>      >> (no active = N).
>      >>
>      >> The tables are the exchange from the client side.
>      >>
>      >> With server side using gen (active = false):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           10192 byte/ms, 154 msgs/ms
>      >>          gen             true            10383 byte/ms, 157 msgs/ms
>      >>          gen             once            6003 byte/ms,  90  msgs/ms
>      >>          sock            false           14050 byte/ms, 212 msgs/ms
>      >>          sock            true            14772 byte/ms, 223 msgs/ms
>      >>          sock            once            14050 byte/ms, 210 msgs/ms
>      >>
>      >>
>      >> With server side using gen (active = true):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           9447 byte/ms,  143 msgs/ms
>      >>          gen             true            22345 byte/ms, 338 msgs/ms
>      >>          gen             once            5532 byte/ms,  83  msgs/ms
>      >>          sock            false           15316 byte/ms, 232 msgs/ms
>      >>          sock            true            23693 byte/ms, 358 msgs/ms
>      >>          sock            once            22068 byte/ms, 334 msgs/ms
>      >>
>      >>
>      >> With server side using sock (active = false, async = true):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           11260 byte/ms, 170 msgs/ms
>      >>          gen             true            22273 byte/ms, 337 msgs/ms
>      >>          gen             once            7703 byte/ms,  116 msgs/ms
>      >>          sock            false           15211 byte/ms, 230 msgs/ms
>      >>          sock            true            24778 byte/ms, 375 msgs/ms
>      >>          sock            once            23086 byte/ms, 349 msgs/ms
>      >>
>      >>
>      >> With server side using sock (active = true, async = true):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           11351 byte/ms, 171 msgs/ms
>      >>          gen             true            22469 byte/ms, 340 msgs/ms
>      >>          gen             once            7407 byte/ms,  112 msgs/ms
>      >>          sock            false           15484 byte/ms, 234 msgs/ms
>      >>          sock            true            24885 byte/ms, 377 msgs/ms
>      >>          sock            once            23570 byte/ms, 357 msgs/ms
>      >>
>      >>
>      >> There is of course a bit of overhead since the socket transport
>      >> is trying to emulate (part of) gen_tcp.
>      >>
>      >> This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
>      >> that effects the relative performance).
>      >> Run with a snapshot from the maint branch.
>      >>
>      >> This is obviously not a real use case, but it can be a guideline.
>      >> Also no UDP test (at the moment).
>      >>
>      >> /BMK
>      >>
>      >> On 2019-10-24 18:48, Frank Muller wrote:
>      >>> Hi Thomas
>      >>>
>      >>> Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share
>     some
>      >>> numbers.
>      >>>
>      >>> /Frank
>      >>>
>      >>>      > case socket:recvfrom(Sock, 0, nowait) of
>      >>>      >       {ok, {#{family := Domain,
>      >>>      >               port   := Port,
>      >>>      >               addr   := Addr}, Data}} ->
>      >>>      >       .
>      >>>
>      >>>     Hi Micael, Mark,
>      >>>
>      >>>     thanks for your replies. The snippet above helped me getting the record
>      >>>     matched.
>      >>>
>      >>>     I'm quite impressed with the socket module, it seems to be pretty
>      >>>     complete, at least for my application.
>      >>>
>      >>>     Thanks,
>      >>>     Thomas
>      >>>
>      >
>
Reply | Threaded
Open this post in threaded view
|

Re: Matching IP address in socket module

I Gusti Ngurah Oka Prinarjaya
Awesome! Can't wait gen_tcp rewritten with new socket module available in public and stable.
And at which version will be available? at 22.X or 23 ?

@Thomas Pircher facing another new problem with socket module. It looks like we hijacked his thread question  ^^ :D

 

Pada tanggal Sel, 29 Okt 2019 pukul 18.09 Micael Karlberg <[hidden email]> menulis:
No, its on the todo list, there is actually a ticket for this.
I would be good for completeness, if nothing else.

/BMK

On 2019-10-29 11:33, pablo platt wrote:
> Micael, are there similar tests for udp?
>
> On Tue, Oct 29, 2019 at 12:12 PM Micael Karlberg <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi,
>
>     Its not a secret :) You will find it in the emulator test catalog.
>     The only problem is that it was never intended for public "consumption"
>     and is therefor not documented:
>
>              socket_test_ttest_tcp_socket.erl (uses socket.erl)
>              socket_test_ttest_tcp_gen.erl    (uses gen_tcp.erl)
>
>     The idea here is that they should have an "identical" interface (so
>     the users should work with both transports).
>     Obviously the "socket" is different (a gen_tcp socket is a port and
>     a socket socket is a term()).
>
>     The other socket_test_ttest_tcp* modules "can" be used to see how to
>     use these...
>
>     Also, there is work on making gen_tcp work with the new socket module.
>     This is ongoing. There is a lot of special options that gen_tcp/inet
>     manages (packaging for instance).
>
>     Regards,
>              /BMK
>
>     On 2019-10-29 10:54, Loïc Hoguin wrote:
>      > Hello,
>      >
>      > I would like to do a similar experiment with RabbitMQ. Would you mind sharing the code that
>     makes
>      > 'socket' work similar to 'gen_tcp'? That may give me a head start, even if the code is not
>     complete.
>      >
>      > Thanks,
>      >
>      > On 25/10/2019 12:39, Micael Karlberg wrote:
>      >> Hi,
>      >>
>      >> Its early days still, but the goal is definitely that it should
>      >> be faster.
>      >>
>      >> Here is some figures from a (time) test tool which is part of the
>      >> test suite (its basically a ping-pong case), both server and client
>      >> running on the same host (but in different VMs):
>      >>
>      >> Two transports:
>      >>          gen:  gen_tcp
>      >>          sock: socket (tcp)
>      >>
>      >> The socket active mode is a simulation of gen_tcp active mode
>      >> (no active = N).
>      >>
>      >> The tables are the exchange from the client side.
>      >>
>      >> With server side using gen (active = false):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           10192 byte/ms, 154 msgs/ms
>      >>          gen             true            10383 byte/ms, 157 msgs/ms
>      >>          gen             once            6003 byte/ms,  90  msgs/ms
>      >>          sock            false           14050 byte/ms, 212 msgs/ms
>      >>          sock            true            14772 byte/ms, 223 msgs/ms
>      >>          sock            once            14050 byte/ms, 210 msgs/ms
>      >>
>      >>
>      >> With server side using gen (active = true):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           9447 byte/ms,  143 msgs/ms
>      >>          gen             true            22345 byte/ms, 338 msgs/ms
>      >>          gen             once            5532 byte/ms,  83  msgs/ms
>      >>          sock            false           15316 byte/ms, 232 msgs/ms
>      >>          sock            true            23693 byte/ms, 358 msgs/ms
>      >>          sock            once            22068 byte/ms, 334 msgs/ms
>      >>
>      >>
>      >> With server side using sock (active = false, async = true):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           11260 byte/ms, 170 msgs/ms
>      >>          gen             true            22273 byte/ms, 337 msgs/ms
>      >>          gen             once            7703 byte/ms,  116 msgs/ms
>      >>          sock            false           15211 byte/ms, 230 msgs/ms
>      >>          sock            true            24778 byte/ms, 375 msgs/ms
>      >>          sock            once            23086 byte/ms, 349 msgs/ms
>      >>
>      >>
>      >> With server side using sock (active = true, async = true):
>      >>
>      >>          Transport       Active          Data
>      >>          gen             false           11351 byte/ms, 171 msgs/ms
>      >>          gen             true            22469 byte/ms, 340 msgs/ms
>      >>          gen             once            7407 byte/ms,  112 msgs/ms
>      >>          sock            false           15484 byte/ms, 234 msgs/ms
>      >>          sock            true            24885 byte/ms, 377 msgs/ms
>      >>          sock            once            23570 byte/ms, 357 msgs/ms
>      >>
>      >>
>      >> There is of course a bit of overhead since the socket transport
>      >> is trying to emulate (part of) gen_tcp.
>      >>
>      >> This is run on a Dell Precision T1700 running SLES 12 SP2 (not that
>      >> that effects the relative performance).
>      >> Run with a snapshot from the maint branch.
>      >>
>      >> This is obviously not a real use case, but it can be a guideline.
>      >> Also no UDP test (at the moment).
>      >>
>      >> /BMK
>      >>
>      >> On 2019-10-24 18:48, Frank Muller wrote:
>      >>> Hi Thomas
>      >>>
>      >>> Is the socket module faster than gen_tcp/gen_udp in your case? If yes, can you please share
>     some
>      >>> numbers.
>      >>>
>      >>> /Frank
>      >>>
>      >>>      > case socket:recvfrom(Sock, 0, nowait) of
>      >>>      >       {ok, {#{family := Domain,
>      >>>      >               port   := Port,
>      >>>      >               addr   := Addr}, Data}} ->
>      >>>      >       .
>      >>>
>      >>>     Hi Micael, Mark,
>      >>>
>      >>>     thanks for your replies. The snippet above helped me getting the record
>      >>>     matched.
>      >>>
>      >>>     I'm quite impressed with the socket module, it seems to be pretty
>      >>>     complete, at least for my application.
>      >>>
>      >>>     Thanks,
>      >>>     Thomas
>      >>>
>      >
>