Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Done
-
None
-
None
Description
When sending image/binary data to a socket the data is base64 encoded and buffered in a way that incurs an excessive number of system calls which can degrade performance.
This occurs in socket.c where guac_socket_write_base64 ends up calling guac_socket_write in a tight loop, once for every 3 bytes being encoded. The system calls this incurs are:
- clock_gettime via guac_timestamp_current
- pthread_mutex_rdlock/unlock via guac_socket_fd_write_handler
Attached an image of VTune profiling which shows that very little time is spent in guac_socket_fd_write_buffered but a lot of time is spent in the syscalls outlined.
Introducing a buffer(~1kb) to append data being encoded prior to writing to the socket results in a performance increase, reducing the time spent on the syscalls. For relative comparison in our test we started with 13fps and by introducing the buffer saw an increase to 23fps.