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

Make ValidatorProvider a Singleton #2864

Merged
merged 2 commits into from Sep 21, 2016
Merged

Make ValidatorProvider a Singleton #2864

merged 2 commits into from Sep 21, 2016

Conversation

bernd
Copy link
Member

@bernd bernd commented Sep 20, 2016

The Validator instance creation is quite expensive. Making this a Singleton reduced the CPU load by 50% and reduced the GC load from 5 GCs per second to 2 GCs per second when running a load test of the collector registration endpoint.

Before

image
image

After

image
image

The Validator instance creation is quite expensive. Making this a
Singleton reduced the CPU load by 50% and reduced the GC load from 5 GCs
per second to 2 GCs per second when running a load test of the collector
registration endpoint.
@bernd bernd added this to the 2.2.0 milestone Sep 20, 2016
@@ -24,6 +24,6 @@
public class ValidatorModule extends AbstractModule {
@Override
protected void configure() {
bind(Validator.class).toProvider(ValidatorProvider.class);
bind(Validator.class).toProvider(ValidatorProvider.class).asEagerSingleton();
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be simpler to directly bind to the instance Validation.buildDefaultValidatorFactory().getValidator() instead of using a singleton provider which basically returns a static field. This way we could get rid of the Provider<Validator>.

https://github.com/google/guice/wiki/InstanceBindings

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will change that.

@bernd
Copy link
Member Author

bernd commented Sep 21, 2016

Updated after review comment.

Copy link
Contributor

@joschi joschi left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@joschi joschi merged commit b82ca3e into master Sep 21, 2016
@joschi joschi deleted the validator-singleton branch September 21, 2016 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants