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

ZOOKEEPER-3242: Add server side connecting throttling #769

Closed
wants to merge 6 commits into from

Conversation

jhuan31
Copy link

@jhuan31 jhuan31 commented Jan 11, 2019

No description provided.

@jhuan31 jhuan31 closed this Jan 12, 2019
@jhuan31 jhuan31 reopened this Jan 12, 2019
@jhuan31 jhuan31 closed this Jan 12, 2019
@jhuan31 jhuan31 reopened this Jan 12, 2019
@jhuan31 jhuan31 closed this Jan 12, 2019
@jhuan31 jhuan31 reopened this Jan 12, 2019
Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Awesome patch @jhuan31 . Thanks for the contribution.
Please add unit tests for BlueThrottle class and documentation about the new properties.

@jhuan31
Copy link
Author

jhuan31 commented Jan 17, 2019

added doc

Copy link
Contributor

@lvfangmin lvfangmin left a comment

Choose a reason for hiding this comment

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

+1 Thanks for adding the docs.

@jhuan31
Copy link
Author

jhuan31 commented Jan 19, 2019

here comes the unit tests

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

Looks good to me, but please take another look at your unit tests.
You might want to do it in a flaky-proof way.

throttler.checkLimit(1);
Assert.assertEquals("All tokens should be used up by now", throttler.getMaxTokens(), throttler.getDeficit());

Thread.sleep(110);
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried to run this tests multiple times? 100x or 1000x ... ?
Tests with Thread.sleep are usually a smell of flaky tests, especially in Apache infra.

Copy link
Author

Choose a reason for hiding this comment

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

I just ran the test 1000 times and it failed once. Yeah, the test is flaky. But I don't think it is because of the sleep. The fillTime and the freezeTime in the test are set to some unrealistic numbers so the test can tolerate some inaccuracy in timing. The test failed because the random number generator for random dropping gave 10 numbers less than 0.5 in a row, an event of of probability EXP(0.5, 10). I'm going to use a mock random generator, which I think is good enough for this unit test.

@jhuan31
Copy link
Author

jhuan31 commented Jan 22, 2019

Ran the unit test 1000 times w/o failure

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

I like the mocked random generator, but still having some nitpicks on the testing side.

readResponseCache = new ResponseCache();

connThrottle = new BlueThrottle();
Copy link
Contributor

Choose a reason for hiding this comment

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

This configuration setting block could be a little bit neater by following the existing pattern in this class: create static constants for the configuration option name and the default value.

The existing config setting intBufferStartingSizeBytes is set via static constructor which is not convenient here, but you could overload the constructor of BlueThrottle to override the default settings. In which case you don't need these setters at all.

Copy link
Author

Choose a reason for hiding this comment

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

Agree. Those setter invocations in the constructor look ugly. Moved them out. But we still need the setters for the JMX interface. And since we are keeping setters, I'd prefer to use them in the unit tests instead of using a constructor with a long list of parameters, i.e, I prefer to explicitly set the refill time to 100 instead of setting the third parameter of the constructor to 100.

class BlueThrottleWithMockRandom extends BlueThrottle {
public BlueThrottleWithMockRandom() {
super();
this.rng = new MockRandom(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could have another overloaded constructor to inject custom random generator.

Copy link
Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

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

+1 LGTM

@asfgit asfgit closed this in 6688285 Jan 23, 2019
@anmolnar
Copy link
Contributor

Merged to master branch. Thanks @jhuan31 !

return true;
}

public synchronized boolean checkBlue(long now) {

Choose a reason for hiding this comment

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

IMO, method checkBlue should have a access level of private since it is only called inside this class.

RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Sep 3, 2022
Author: Jie Huang <[email protected]>

Reviewers: [email protected], [email protected]

Closes apache#769 from jhuan31/ZOOKEEPER-3242 and squashes the following commits:

c3ec81f [Jie Huang] refactoring
86cad39 [Jie Huang] Use a mock random number generator to make the unit test flaky-proof
a278504 [Jie Huang] Add unit tests for server-side connection throttling
fd96650 [Jie Huang] update doc for server-side connection throttling
2f1ed0b [Jie Huang] Fix FindBugs Warnings
a48b0fc [Jie Huang] ZOOKEEPER-3242: Add server side connecting throttling
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.

4 participants