adrienmo / eredis_cluster

eredis_cluster is an erlang wrapper for eredis to support cluster mode of redis 3.0.0+
MIT License
79 stars 83 forks source link

Improve slot table access performance #45

Closed aboroska closed 4 years ago

aboroska commented 4 years ago

Commit 8def1a7a542 (part of 0.5.12) already improved the performance of qmn queries compared to 0.5.11.

This commit improves it again compared to 0.5.12 because it turnes out that reading the large slots tuple with 16384 elements from ETS forces the runtime system to perform too many garbage collections. The solution removes the large tuple from State and stores the mapping in an ETS table as {k, v} pairs.

Performance tested on AWS m5.x2large instance with 8 cores. Erlang 22.3.2

Rough numbers for qmn read (@ ~4200 req/seq):

Rough numbers for qmn write (@ ~3300 req/seq):

Even though as a side effect of the solution the slot table update is not atomic anymore it will not cause issues as the current retry logic of MOVED responses should handle it already.

image

Also tested a version where slots were sharded to 128 ETS tables and also one using process dictionary (not shown on the graph above) with similar results.

adrienmo commented 4 years ago

@aboroska Thanks for your contribution!