Hi,
I have been benchmarking and profiling libreactor to try and find any potential optimizations for what is already a very, very fast framework.
In my tests using the Techempower JSON benchmark running on an AWS EC2 instance, I was able to achieve a performance improvement of a little over 10% by using the send/recv functions (with the flags param set to 0) in place of write/read.
From the attached flamegraphs (see below) of the syscalls made during the test, you can see that sys_read/sys_write call several intermediate functions before finally calling inet_recvmsg and sock_sendmsg. So even though the behavior is functionally identical, there is a performance gain to be had that shows up tests like this.
I would like to create a PR for libreactor where reactor_stream_flush and reactor_stream_input conditionally use send and recv if the steam in question is known to be a socket. However I wanted to find out what your preferred approach would be.
One approach could be to add a new member to the reactor_stream struct called is_socket. That value could be initialized when reactor_stream_open is called, either by passing and additional parameter or checking it automatically using fstat/S_ISSOCK. I just wanted to get you feedback before I created a PR.
FYI I also tried using sendto and sendmsg. The performance of sendto was the same and sendmsg was actually worse.
write/read

send/recv

Hi,
I have been benchmarking and profiling libreactor to try and find any potential optimizations for what is already a very, very fast framework.
In my tests using the Techempower JSON benchmark running on an AWS EC2 instance, I was able to achieve a performance improvement of a little over 10% by using the
send/recvfunctions (with the flags param set to 0) in place ofwrite/read.From the attached flamegraphs (see below) of the syscalls made during the test, you can see that sys_read/sys_write call several intermediate functions before finally calling
inet_recvmsgandsock_sendmsg. So even though the behavior is functionally identical, there is a performance gain to be had that shows up tests like this.I would like to create a PR for libreactor where
reactor_stream_flushandreactor_stream_inputconditionally usesendandrecvif the steam in question is known to be a socket. However I wanted to find out what your preferred approach would be.One approach could be to add a new member to the
reactor_streamstruct calledis_socket. That value could be initialized whenreactor_stream_openis called, either by passing and additional parameter or checking it automatically usingfstat/S_ISSOCK. I just wanted to get you feedback before I created a PR.FYI I also tried using
sendtoandsendmsg. The performance ofsendtowas the same andsendmsgwas actually worse.write/read

send/recv
