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

Flat tree with binary-content nodes implementation of max-rate registry #1086

Merged
merged 11 commits into from Aug 22, 2019

Conversation

dankraw
Copy link
Contributor

@dankraw dankraw commented Aug 14, 2019

Introducing alternative implementation for max-rate registry in which we keep whole max-rate configuration dedicated to a single consumer in just one znode:
/hermes/consumers-rate/<cluster>/runtime-bin/<consumer-id>/max-rate
On the other hand consumer writes its current sending rate to a single znode:
/hermes/consumers-rate/<cluster>/runtime-bin/<consumer-id>/history

These znodes are encoded in binary format (using SBE) and use numeric ids for subscription identification.

The leader node reads history znodes of all consumers on each max-rate computation. After the computations are done, it saves the results to max-rate znodes, so consumers can update their sending max-rates.

By using this registry implementation we generate much less znodes in zookeeper and need few zookeeper watches, the structure is flat and should load very fast and take not much space even for thousands of subscriptions controlled by a single consumer node. The number of znodes grows linearly as the number of consumers grow. I haven't implemented any zookeeper watches except a single NodeCache per consumer node, so it is immediately notified about max-rate being changed by the leader. Maybe in the future it will be worth implementing a PathChildrenCache just for the leader node.

HierarchicalCacheMaxRateRegistry is basically old MaxRateRegistry class, it's just renamed, as MaxRateRegistry is now an interface, so different implementations are available to choose from. Personally, I think the interface is too wide, but I wanted to leave it as is for now, so we don't change too much in the old max-rate implementation. If we stop supporting it, it will be easy to refactor and for example divide the registry into two parts: one for the leader that makes all the computations (so it reads history znodes of all consumers in its cluster), and second for all the nodes other nodes in which only max-rate znode is loaded and rate history znode is updated.

Note: all classes from pl.allegro.tech.hermes.consumers.consumer.rate.sbe.stubs package are generated using SBE build tool via ./gradlew hermes-consumers:generateSbeStubs.
Schema configuration files that the stubs are generated from are kept in hermes-consumers/src/main/resources/sbe/ directory.

Copy link
Contributor

@cristaloleg cristaloleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

&& !maxRateRegistry.getMaxRate(new ConsumerInstance(consumerId, subscription2)).isPresent()));
}

@Test(expected = IllegalStateException.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noice

@dankraw dankraw merged commit 4c3c823 into master Aug 22, 2019
@cristaloleg cristaloleg deleted the maxrate-sbe branch September 27, 2019 11:20
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.

None yet

3 participants