Skip to content

ZOOKEEPER-3503: Add server side large request throttling#1051

Closed
jhuan31 wants to merge 2 commits intoapache:masterfrom
jhuan31:ZOOKEEPER-3503
Closed

ZOOKEEPER-3503: Add server side large request throttling#1051
jhuan31 wants to merge 2 commits intoapache:masterfrom
jhuan31:ZOOKEEPER-3503

Conversation

@jhuan31
Copy link
Copy Markdown

@jhuan31 jhuan31 commented Aug 11, 2019

With this change, a ZooKeeper server has two new settings:
zookeeper.largeRequestThreshold
zookeeper.largeRequestMaxBytes

Any request that is larger than largeRequestThreshold is considered a large request, and will only be allowed if the number of bytes associated with inflight large requests is currently below the largeRequestMaxBytes limit.

This check is performed in the connection layer based on the length header of a request, before allocating the necessary byte buffer and reading data off the TCP socket. This ensures the limit is enforced before allocating data that's ultimately just going to discarded.

Whenever a large request is allowed, its size is added to an atomic counter which represents the number of large request bytes inflight and this counter is the one tested against the max. Whenever a large request is completed or dropped, the counter is decremented as necessary.

@jhuan31 jhuan31 force-pushed the ZOOKEEPER-3503 branch 2 times, most recently from aa972bf to b854c35 Compare August 11, 2019 14:18
return length > largeRequestThreshold;
}

private boolean testRequestSize(int length, boolean increment) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

having a boolean parameter in a function seems an anti pattern to me.

Is there a case when we don't want increment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We check while receiving the packet and after we receive the whole packet. We increment only after we receive the whole packet. I refactor the code. Let me know whether it is easier to read.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, i think although the new code is a little bit verbose it's easier to understand.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One nit - we could use void return type instead of boolean as these check function will never return false. Though, current form is ok to me too.

* The size threshold after which a request is considered a large request
* and is checked against the large request byte limit.
*/
private volatile int largeRequestThreshold =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's necessary to do a validation of the values on these two newly added property, and throw argument exceptions if they are off the chart (and update doc to reflect the valid ranges.).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I add some basic checking and printing the current settings to the log. It's really hard to say what the valid ranges should be. Also I feel throwing an exception is a little too harsh. I just disable the large request throttling if the values are wrong. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good to me, as this feature is not about correctness so even if it's misconfigured it's ok to have the cluster running with warning messages printed in log.

@jhuan31 jhuan31 changed the title Add server side large request throttling ZOOKEEPER-3503: Add server side large request throttling Aug 13, 2019
@jhuan31 jhuan31 force-pushed the ZOOKEEPER-3503 branch 2 times, most recently from ddf2bae to 5045558 Compare August 30, 2019 22:14
@hanm
Copy link
Copy Markdown
Contributor

hanm commented Sep 5, 2019

this is ready to land. just needs a rebase to resolve the documentation conflict. @jhuan31

@jhuan31
Copy link
Copy Markdown
Author

jhuan31 commented Sep 16, 2019

Thank you for the reminder @hanm ! Just rebased

@asfgit asfgit closed this in 1ca627b Sep 16, 2019
stickyhipp pushed a commit to stickyhipp/zookeeper that referenced this pull request Aug 19, 2020
With this change, a ZooKeeper server has two new settings:
zookeeper.largeRequestThreshold
zookeeper.largeRequestMaxBytes

Any request that is larger than largeRequestThreshold is considered a large request, and will only be allowed if the number of bytes associated with inflight large requests is currently below the largeRequestMaxBytes limit.

This check is performed in the connection layer based on the length header of a request, before allocating the necessary byte buffer and reading data off the TCP socket. This ensures the limit is enforced before allocating data that's ultimately just going to discarded.

Whenever a large request is allowed, its size is added to an atomic counter which represents the number of large request bytes inflight and this counter is the one tested against the max. Whenever a large request is completed or dropped, the counter is decremented as necessary.

Author: Jie Huang <jiehuang@fb.com>
Author: Joseph Blomstedt <jdb@fb.com>

Reviewers: Michael Han <hanm@apache.org>, Norbert Kalmar <nkalmar@apache.org>

Closes apache#1051 from jhuan31/ZOOKEEPER-3503
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Aug 31, 2022
With this change, a ZooKeeper server has two new settings:
zookeeper.largeRequestThreshold
zookeeper.largeRequestMaxBytes

Any request that is larger than largeRequestThreshold is considered a large request, and will only be allowed if the number of bytes associated with inflight large requests is currently below the largeRequestMaxBytes limit.

This check is performed in the connection layer based on the length header of a request, before allocating the necessary byte buffer and reading data off the TCP socket. This ensures the limit is enforced before allocating data that's ultimately just going to discarded.

Whenever a large request is allowed, its size is added to an atomic counter which represents the number of large request bytes inflight and this counter is the one tested against the max. Whenever a large request is completed or dropped, the counter is decremented as necessary.

Author: Jie Huang <jiehuang@fb.com>
Author: Joseph Blomstedt <jdb@fb.com>

Reviewers: Michael Han <hanm@apache.org>, Norbert Kalmar <nkalmar@apache.org>

Closes apache#1051 from jhuan31/ZOOKEEPER-3503
RokLenarcic pushed a commit to RokLenarcic/zookeeper that referenced this pull request Sep 3, 2022
With this change, a ZooKeeper server has two new settings:
zookeeper.largeRequestThreshold
zookeeper.largeRequestMaxBytes

Any request that is larger than largeRequestThreshold is considered a large request, and will only be allowed if the number of bytes associated with inflight large requests is currently below the largeRequestMaxBytes limit.

This check is performed in the connection layer based on the length header of a request, before allocating the necessary byte buffer and reading data off the TCP socket. This ensures the limit is enforced before allocating data that's ultimately just going to discarded.

Whenever a large request is allowed, its size is added to an atomic counter which represents the number of large request bytes inflight and this counter is the one tested against the max. Whenever a large request is completed or dropped, the counter is decremented as necessary.

Author: Jie Huang <jiehuang@fb.com>
Author: Joseph Blomstedt <jdb@fb.com>

Reviewers: Michael Han <hanm@apache.org>, Norbert Kalmar <nkalmar@apache.org>

Closes apache#1051 from jhuan31/ZOOKEEPER-3503
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