Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Partitions/RedisClusterNode representation #715

Closed
mp911de opened this issue Feb 27, 2018 · 2 comments
Closed

Optimize Partitions/RedisClusterNode representation #715

mp911de opened this issue Feb 27, 2018 · 2 comments
Labels
type: feature A new feature

Comments

@mp911de
Copy link
Collaborator

mp911de commented Feb 27, 2018

A partitions object with a single node holding all 16384 slots requires about 300000 bytes, most of that is used by the slot list.

screenshot 2018-02-27 14 52 59

We should investigate whether a slot set (storing slots as bits, similar to a jumbo EnumSet holding states in 256 long values) could help here.

@mp911de
Copy link
Collaborator Author

mp911de commented Mar 12, 2018

Benchmarks:

Backed by BitSet

Benchmark                                              Mode  Cnt      Score      Error  Units
RedisClusterNodeBenchmark.createClusterNodeAllSlots    avgt    5  42519,671 ± 1496,360  ns/op
RedisClusterNodeBenchmark.createClusterNodeLowerSlots  avgt    5  21140,743 ±  757,166  ns/op
RedisClusterNodeBenchmark.querySlotStatusAbsent        avgt    5      0,910 ±    0,045  ns/op
RedisClusterNodeBenchmark.querySlotStatusPresent       avgt    5      0,869 ±    0,044  ns/op

Backed by List<Integer>

Benchmark                                              Mode  Cnt     Score      Error  Units
RedisClusterNodeBenchmark.createClusterNodeAllSlots    avgt    5     8,263 ±    0,364  ns/op
RedisClusterNodeBenchmark.createClusterNodeLowerSlots  avgt    5     8,329 ±    0,681  ns/op
RedisClusterNodeBenchmark.querySlotStatusAbsent        avgt    5  5833,627 ± 1061,461  ns/op
RedisClusterNodeBenchmark.querySlotStatusPresent       avgt    5   804,903 ±   60,666  ns/op

@mp911de mp911de added the type: feature A new feature label Mar 12, 2018
@mp911de mp911de added this to the Lettuce 4.5.0 milestone Mar 12, 2018
@mp911de
Copy link
Collaborator Author

mp911de commented Mar 12, 2018

Memory consumption after the change:

screenshot 2018-03-12 09 55 19

mp911de added a commit that referenced this issue Mar 12, 2018
Lettuce now uses BitSet to represent internally cluster slots assigned to a cluster node. The slot storage is allocated lazily and nodes without a slot (non-slot masters, slave nodes) won't allocate any memory for the slot storage.

This change reduces the memory usage from the previously used ArrayList with initially 16 elements backed by an Object[]. A node with all slots assigned required about 325.000 bytes of memory.

Using a BitSet stores only bitwise whether a slot is assigned or not. The storage requires a fixed amount of memory (about 2184 bytes) for each node independent of how many slots are occupied. A cluster of 150 nodes reached the break-even between the previous and current pattern if at least a single slot is used on a particular node. Clusters with more nodes will have always a higher memory consumption if at least a single slot is occupied.
mp911de added a commit that referenced this issue Mar 12, 2018
Lettuce now uses BitSet to represent internally cluster slots assigned to a cluster node. The slot storage is allocated lazily and nodes without a slot (non-slot masters, slave nodes) won't allocate any memory for the slot storage.

This change reduces the memory usage from the previously used ArrayList with initially 16 elements backed by an Object[]. A node with all slots assigned required about 325.000 bytes of memory.

Using a BitSet stores only bitwise whether a slot is assigned or not. The storage requires a fixed amount of memory (about 2184 bytes) for each node independent of how many slots are occupied. A cluster of 150 nodes reached the break-even between the previous and current pattern if at least a single slot is used on a particular node. Clusters with more nodes will have always a higher memory consumption if at least a single slot is occupied.
mp911de added a commit that referenced this issue Mar 12, 2018
Lettuce now uses BitSet to represent internally cluster slots assigned to a cluster node. The slot storage is allocated lazily and nodes without a slot (non-slot masters, slave nodes) won't allocate any memory for the slot storage.

This change reduces the memory usage from the previously used ArrayList with initially 16 elements backed by an Object[]. A node with all slots assigned required about 325.000 bytes of memory.

Using a BitSet stores only bitwise whether a slot is assigned or not. The storage requires a fixed amount of memory (about 2184 bytes) for each node independent of how many slots are occupied. A cluster of 150 nodes reached the break-even between the previous and current pattern if at least a single slot is used on a particular node. Clusters with more nodes will have always a higher memory consumption if at least a single slot is occupied.
@mp911de mp911de closed this as completed Mar 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new feature
Projects
None yet
Development

No branches or pull requests

1 participant