CommandRegistry performance improvement
motivation:
- All commands are predefined and we use them only to read so we can create a more efficient hash table that will be stored in one memory chunk. It significantly improves temporal cache locality. Customers, in most cases, use quite a small list of commands.
- Commands are not equal. We can split all commands into 2 types:
- performance-oriented (set / get / find / calculate)
- service commands (info / cluster / replica)
The way for improvement:
- The hash table can be created by string size and do faster comparisons in this case with fixed size (for example, strings less than 8 bytes can be compared as integers).
- Performance-oriented commands should be checked before service commands. In this case, the cache will be utilized more efficiently.
Two questions!
-
Why would we care about the performance of CommandRegistry? Have we ever noticed/seen that command lookup in the registry is a considerable bottleneck ? My two cents is that it is not. I see way more low hanging fruits that come from the design. For example proactor dispatch and multi hop operations, replying on single key commands on the dispatched proactor instead of doing the "hop" etc and I would expect that that there are more interesting optimizations there than the commend registry.
-
What do you mean by:
if-else construction for predefined strings can be easily transformed by a compiler into a hash table by string size and make comparisons as integers
Commands are executed at runtime, so the compiler knows nothing about transforming that string into an integer? Can you plz elaborate?
- when I measured it was near 1% for CommandRegistry lookup. I agree that it's not critical but like an option.
- if you know the size of the string the string is just copied into the register and the whole string compares at once like an integer.
when I measured it was near 1% for CommandRegistry lookup.
You can benchmark performance with the command registry vs a stub that always returns the correct command without lookup. Choosing a command like PING will be the least load scenario