Skip to content

Support http read timeouts for transport-nio #41466

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

Merged
merged 18 commits into from
May 1, 2019

Conversation

Tim-Brooks
Copy link
Contributor

This is related to #27260. Currently there is a setting
http.read_timeout that allows users to define a read timeout for the
http transport. This commit implements support for this functionality
with the transport-nio plugin. The behavior here is that a repeating
task will be scheduled for the interval defined. If there have been
no requests received since the last run and there are no inflight
requests, the channel will be closed.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

Copy link
Contributor

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

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

2 nits and a suggested simplification :)

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

lefts some comments

@Tim-Brooks
Copy link
Contributor Author

@s1monw @original-brownbear - I made your changes. Thanks.

Copy link
Contributor

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

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

Changes look good except for the added method on ThreadPool, let me know what you think there.

* timestamp, see {@link #absoluteTimeInMillis()}.
*/
public long relativeTimeInNanos() {
return TimeValue.msecToNSec(cachedTimeThread.relativeTimeInMillis());
Copy link
Contributor

Choose a reason for hiding this comment

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

@tbrooks8 I'm not sure we should add this. The underlying logic as it is coded up now isn't nano second precise.
We could adjust CachedTimeThread to return nano second precision times and only add the rounding to ms in the existing relativeTimeInMillis method?
But then again, maybe we don't need ns for the http timeout in the first place and can just work with ms precision and not add more complication to the ThreadPool class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could adjust CachedTimeThread to return nano second precision times and only add the rounding to ms in the existing relativeTimeInMillis method?

I think this is the correct approach, but I hesitated to change it in this PR as the behavior of the timer tick thread might be of concern to other people. Anyway, I will make that change and we can discuss.

Copy link
Contributor Author

@Tim-Brooks Tim-Brooks Apr 25, 2019

Choose a reason for hiding this comment

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

Anyway, I made this change.

  1. We need nanoseconds. TaskScheduler deals in nanoseconds.
  2. If we do the conversion outside of the ThreadPool we depend on the fact that ThreadPool will always return a relative millis value that can be successfully converted to nanoseconds. Obviously this is the case as the value originates from nanotime, but I prefer to not depend on that fact. Which is why I prefer that ThreadPool returns nanotime (similar to the fact that most Java relative time calculations are made using nanotime).
  3. The cost of the change is division every time you want millis. I assume this is fine, but obviously the entire point of this tick thread is to replace a System.nanotime call with a volatile read at the cost of resolution. So maybe there is some objection. We could also store a precalculated version in millis.

@original-brownbear
Copy link
Contributor

thanks @tbrooks8 LGTM now

@ywelsch
Copy link
Contributor

ywelsch commented Apr 26, 2019

/cc @andrershov that we can as part of the netty vs nio benchmarking check whether enabling http read timeouts have any effect either way.

Copy link
Contributor

@ywelsch ywelsch left a comment

Choose a reason for hiding this comment

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

With my limited understanding of this, I mainly looked at it to learn a few things about the NIO implementation.

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

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

LGTM

@Tim-Brooks
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/1

@Tim-Brooks
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/2

@Tim-Brooks Tim-Brooks merged commit 5309c6c into elastic:master May 1, 2019
Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request May 1, 2019
This is related to elastic#27260. Currently there is a setting
http.read_timeout that allows users to define a read timeout for the
http transport. This commit implements support for this functionality
with the transport-nio plugin. The behavior here is that a repeating
task will be scheduled for the interval defined. If there have been
no requests received since the last run and there are no inflight
requests, the channel will be closed.
akhil10x5 pushed a commit to akhil10x5/elasticsearch that referenced this pull request May 2, 2019
This is related to elastic#27260. Currently there is a setting
http.read_timeout that allows users to define a read timeout for the
http transport. This commit implements support for this functionality
with the transport-nio plugin. The behavior here is that a repeating
task will be scheduled for the interval defined. If there have been
no requests received since the last run and there are no inflight
requests, the channel will be closed.
Tim-Brooks added a commit that referenced this pull request May 2, 2019
This is related to #27260. Currently there is a setting
http.read_timeout that allows users to define a read timeout for the
http transport. This commit implements support for this functionality
with the transport-nio plugin. The behavior here is that a repeating
task will be scheduled for the interval defined. If there have been
no requests received since the last run and there are no inflight
requests, the channel will be closed.
gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this pull request May 27, 2019
This is related to elastic#27260. Currently there is a setting
http.read_timeout that allows users to define a read timeout for the
http transport. This commit implements support for this functionality
with the transport-nio plugin. The behavior here is that a repeating
task will be scheduled for the interval defined. If there have been
no requests received since the last run and there are no inflight
requests, the channel will be closed.
@Tim-Brooks Tim-Brooks deleted the nio_http_read_timeouts branch December 18, 2019 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants