NIO2: Call accept
immediately if connection count is not close to max con…
#371
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…nections
Under regular load, we observe NIO2 has better CPU utilization and slightly better latency compared to NIO1. However, under heavy load or during spikes, we observed that the 99th percentile latency of NIO2 is significantly worse compared to NIO1.
maxKeepAliveRequests=-1
, we do not observe the latency degradation with NIO2 at all. But, we need and use Tomcat’smaxKeepAliveRequests
feature, so setting it to-1
is not an option.While looking at Tomcat code, we saw that the
accept
is scheduled to be run on the thread pool. Our hypothesis was that this scheduling was causing theaccept
to be delayed significantly under heavy load. So, for a request with new connection establishment, it needs to go through theTaskQueue
twice. So, just for testing purpose we setmaxConnections=-1
to see the impact of immediateaccept
call (and in our test the number of concurrent connections does not get close tomaxConnections
), we observed that the 99th percentile latency problem with NIO2 disappeared.Accordingly, proposing a change to call
accept
immediately if the number of connections are not close tomaxConnections
.