Skip to content

Conversation

@jminarik-atl
Copy link

@jminarik-atl jminarik-atl commented Jul 4, 2023

We use this on a client where our ring contains ~ 200 nodes. With 160 replicas, that is 32,000 items in the ring. CPU profiling has revealed that calling Object.keys(this.ring) turned out to be expensive when called frequently (called twice in getNode())

@jminarik-atl
Copy link
Author

Benchmark results

ORIGINAL should get correct ring length (27082 ms)
FAST should get correct ring length (167 ms)

Benchmark code:

describe('Faster Consistent Hashing class', () => {
  const nodes = Array(200)
    .fill(1)
    .map((_, idx) => idx);
  const chash = new ConsistentHashing(nodes);
  const chashFast = new FastConsistentHashing(nodes);
  it('ORIGINAL should get correct ring length', async () => {
    await benchmark.record(
      () => {
        chash.getRingLength();
      },
      { iterations: 10000 },
    );
  });
  it('FAST should get correct ring length', async () => {
    await benchmark.record(
      () => {
        chashFast.getRingLength();
      },
      { iterations: 10000 },
    );
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant