sccn / liblsl

C++ lsl library for multi-modal time-synched data transmission over the local network
Other
107 stars 63 forks source link

Synchronous Outlet for zero-copying socket writing #153

Closed cboulay closed 2 years ago

cboulay commented 2 years ago

This implements a code path that allows for synchronous (blocked) calls to push_* by setting an outlet constructor argument do_async to false or 0. In this path, liblsl performs 0 (zero) copies on the data, compared to the 2 copies performed wen doing asynchronous writing. This can have dramatic speed / CPU usage improvements when using high bandwidth data (18%->5% in one of my tests).

Note that this contains some commits from the double_buflen branch. Currently the only relevant commit to examine is c64aeb9.

Some concerns:

cboulay commented 2 years ago

Disabling the transfer_samples_thread leads to errors on the inlet at chunk boundaries on line https://github.com/sccn/liblsl/blob/cboulay/outlet_sync/src/data_receiver.cpp#L317-L318 . If I leave the do-nothing thread in place then it seems to work fine. :shrug:

cboulay commented 2 years ago

Note to self: disable synchronous-write-mode when data format is string or when byte order is not default.

cboulay commented 2 years ago

Thanks @tstenner for pointing out that the transfer_samples_thread becomes the sole owner of the client_session. Without the thread we would need the client_session to exist elsewhere. Maybe in a container with the socket? I don't know yet.

cboulay commented 2 years ago

Rebased on #146 which was recently rebased on #155. Still a little work to do here.

cboulay commented 2 years ago

I made some changes based on your suggestions. However, the multiple-client code is probably still broken. I had to deprioritize that due to time constraints. I hope to get back to this soon.

cboulay commented 2 years ago

I discovered that outlet.have_consumers doesn't work properly in sync mode.

cboulay commented 2 years ago

Closing in favour of #170