A Redis clone written in C/C++ from scratch. Practice makes perfect!
-
Use epoll instead of poll in the event loop.
-
Optimize the use of memmove in the read buffer.
We are usingmemmove
to reclaim read buffer space. However, usingmemmove
on every request is unnecessary. Change the code to performmemmove
only before reading. -
Improve the write process in the
state_res
function.
In thestate_res
function, write was performed for a single response. In pipelined scenarios, we could buffer multiple responses and flush them at the end with a single write call. Note that the write buffer could be full in the middle.