Fix performance issues on socket layer
Problem
Performances issues were detected on windows platform on which read / write performance tests are 15x slower than on Linux.
- Linux: ~1ms
- Windows: ~15ms
Analysis
The performances issue is due to the fact the we actually read data on socket in a second thread and we remove the socket from the read set in the socket network events waiting the read to be done. In this latter case another cycle could be awaited before adding again the socket in the read set which can lead to delay in treatment of new data received.
Resolution
Quick fix
A quick fix consists in moving the actual data reading on socket in the loop managing the socket network events. It will fix this particular issue of performance but could still lead to wait for next cycle in others cases (new connection to a server, accepting connection from a server, adding a socket to write set).
Performances improvement:
- Linux: ~0.2ms
- Windows: ~0.2ms
Long term fixes
Still to be defined precisely:
- Make
select
on socket blocking instead of using timeout but add a way to interrupt the select when it is needed - Manage socket layer in a unique thread to avoid synchronization issues, interrupt select on internal events received to treat them before an external event occurs (treat all internal events before external to avoid ignoring close socket request)
- Manage timers evaluation in a separated thread