GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||
GeezerVison is showing github.com — Introduce IoHandleEventLoopGroup / IoHandleEventLoop and its implemen… by normanmaurer · Pull Request #13991 · netty/netty Conversation
Member
…tations MultiThreadIoHandleEventLoopGroup / SingleThreadIoHandleEventLoop Motivation: At the moment each transport has its own EventLoopGroup and EventLoop implementation. Most of these are final because they are tightly coubled with the specific Channel implementations. This is unfortunate for multiple reasons, as for example:
Modifications:
Result: More code sharing and easier of customizing EventLoops.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
I am opening this a draft mainly because I wanted to show and proof that we can back port some of the changes that we did in main without breaking too much things. I think even thought this PR introduce some API breaking it shouldn’t affect almost any user. To proof this I did not change how we create the different EventLoopGroups in our testsuite and everything still works. So while the old way of constructing Eventloops still work the new way would be a bit different: Old API: New API: The benefit of the new way is that it is quite easy to instrument / doctorate an EventLoop/EventLoopGroup now. Basically you can just extend MultiThreadIoHandleEventLoopGroup / SingleThreadIoHandleEventLoop and add all the customization once while be able to reuse it with any transport implementation.
Beside this IoHandleEventLoop can support not only Channel but also other subtypes of IoHandle. This would for example allow us to add file io support with io_uring and still use the same eventloop as for sockets etc. I am sure there are more things we could do by adding this kind of flexibility. With all this said I still think the change is too dangerous for a new 4.1.x release. With this in mind I wondered if we might want to aim for releasing 4.2.0 with the following change:
I would love to hear what other project members and the community think about this ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@bryce-anderson @idelpivnitskiy @chrisvest @franz1981 @vietj @yawkat @trustin WDYT ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
If interested I can also change all the creation code of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…tations MultiThreadIoHandleEventLoopGroup / SingleThreadIoHandleEventLoop Motivation: At the moment each transport has its own EventLoopGroup and EventLoop implementation. Most of these are final because they are tightly coubled with the specific Channel implementations. This is unfortunate for multiple reasons, as for example: - It's hard to instrument EventLoop* implementations as these are not extensible at all or even if they are the same logic needs to be added to multiple EventLoop* implementations. - Registration / Deregistration is limited to Channels which remove flexibility as for example some Operation Systems allowing to also handle other IO (for example file IO) with something like an EventLoop (one example would be io_uring). - A lot of code-duplication between different EventLoop* implementations exists as most share kind of the same logic of running non IO tasks. Modifications: - Add the concept of IoHandleEventLoopGroup / IoHandleEventLoop and the corrosponding IoHandle, IoHandler and IoHandlerFactory. This allows to only have a custom implement for IO handling per transport while share the same code for execution of tasks, scheduled task and ultimatly IO. - Add the implementations MultiThreadIoHandleEventLoopGroup and SingleThreadIoHandleEventLoop that can be used by all (or most) transport implementations by having these just provide their own IoHandler / IoHandlerFactory implementations. Result: More code sharing and easier of customizing EventLoops.
2620422 to
e9c9852
Compare
|
Do you plan to align with the design in Netty 5? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| for (EventExecutor e: this) { | ||
| ((EpollEventLoop) e).setIoRatio(ioRatio); | ||
| } | ||
| // NOOP |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same here, need to document that this does nothing now
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Will look into the build timeout later today |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
What design you talk about ? The ideas was to introduce the same concept with minimal real world breakage |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I mean split the ioHandler with the event loop, I will take some time to look into this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That's exactly what this PR does ;) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Also I think if we would switch to java8 I could maybe do something more flexible to support different |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@normanmaurer I don't know whether we should discuss this here in this PR but
Have you considered moving out of incubation some of the projects? (io_uring, QUIC, HTTP/3)? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yes but let's focus on this one first :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I would like to +1 for moving to Java 8 on Netty 4.2.x, as Netty 4.1.x has a very long history, With Java 8's default method, lambda completableFuture, etc., we can achieve more than it is now. We can submit a PR and wait to see if people complain about moving to Java 8 on Netty 4.2.x |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
I think we should definitely try or even use 11. Let's discuss about this as a followup. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A few comments
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks a lot for all the reviews.... This is now merged :) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ucting it Motiviation: #13991 introduced a new way of how EventLoopGroups should be constructed. We should update our code to use the new way in examples and tests Modifications: Rewrite all tests / example to use new way of constructing Result: Cleanup
…ucting it Motiviation: #13991 introduced a new way of how EventLoopGroups should be constructed. We should update our code to use the new way in examples and tests Modifications: Rewrite all tests / example to use new way of constructing Result: Cleanup
…ructing it (#14020) Motiviation: netty/netty#13991 introduced a new way of how EventLoopGroups should be constructed. We should update our code to use the new way in examples and tests Modifications: Rewrite all tests / example to use new way of constructing Result: Cleanup
…ventLoop (#17481) Motivation: The unification done in #13991/#14557 replaced the per-transport ioRatio scheduling with a fixed maxTaskProcessingQuantumMs cap on task processing before returning to IO. Under sustained load the task queue is never empty, so the event loop can spend up to the full quantum on tasks every iteration regardless of how little time was just spent on IO, delaying IO servicing (and so response completion) for a minority of requests. This was observed as an elevated mean (but not median) round-trip latency after upgrading from 4.1 to 4.2, which went away on rollback. Modifications: - Add back a volatile ioRatio field and functional getIoRatio()/ setIoRatio(int) on SingleThreadIoEventLoop, configurable via the new io.netty.eventLoop.ioRatio system property (default 100, which preserves the current fixed-quantum behaviour unchanged). - When ioRatio < 100, size each iteration's task budget as ioTime * (100 - ioRatio) / ioRatio, capped by maxTaskProcessingQuantumNs, matching the pre-4.2 NioEventLoop formula while keeping the existing quantum as a safety upper bound. - Add setter / getter to MultiThreadIoEventLoopGroup so it is supported globally Result: Users hitting the 4.2 scheduling regression can restore proportional IO/task balancing with a single setIoRatio(50) call (or the new system property), with no change in behaviour for anyone who doesn't opt in.
…eadIoEventLoop (#17481) (#17603) Motivation: The unification done in #13991/#14557 replaced the per-transport ioRatio scheduling with a fixed maxTaskProcessingQuantumMs cap on task processing before returning to IO. Under sustained load the task queue is never empty, so the event loop can spend up to the full quantum on tasks every iteration regardless of how little time was just spent on IO, delaying IO servicing (and so response completion) for a minority of requests. This was observed as an elevated mean (but not median) round-trip latency after upgrading from 4.1 to 4.2, which went away on rollback. Modifications: - Add back a volatile ioRatio field and functional getIoRatio()/ setIoRatio(int) on SingleThreadIoEventLoop, configurable via the new io.netty.eventLoop.ioRatio system property (default 100, which preserves the current fixed-quantum behaviour unchanged). - When ioRatio < 100, size each iteration's task budget as ioTime * (100 - ioRatio) / ioRatio, capped by maxTaskProcessingQuantumNs, matching the pre-4.2 NioEventLoop formula while keeping the existing quantum as a safety upper bound. - Add setter / getter to MultiThreadIoEventLoopGroup so it is supported globally Result: Users hitting the 4.2 scheduling regression can restore proportional IO/task balancing with a single setIoRatio(50) call (or the new system property), with no change in behaviour for anyone who doesn't opt in.
Motivation: NioIoHandler.millisBeforeDeadline(...) adds 500_000 ns before dividing by 1_000_000, which rounds to the nearest millisecond, while the comment says it rounds up. If the next scheduled task is less than 0.5 ms away the timeout is 0, so select(...) calls selectNow() and returns. The task is not due yet, so the event loop runs another iteration and does the same again until the deadline is reached. An event loop that has I/O and a pending timer therefore polls the selector in a loop: an application with a timer that fires every ms, 4 event loops and 4000 requests/s used about 3 times the CPU of 4.1, with 8 times as many epoll_wait calls. NioEventLoop in 4.1 rounds up (deadline + 995000) since netty#9799, so the timeout is only 0 if the deadline is within 5 microseconds. The 4.2 NioIoHandler was introduced (netty#13991) with the older rounding. Modification: Add 995_000 instead of 500_000 and adjust the overflow guard to the new bias. Make the method package private so it can be tested. Result: The event loop sleeps in Selector.select(...) until the deadline instead of spinning. Timers can fire up to 1 ms later than before, like in 4.1. The epoll, kqueue and io_uring transports use nanosecond timeouts and are not affected. Assisted-by: Claude Opus 5.5 <[email protected]>
Motivation: NioIoHandler.millisBeforeDeadline(...) adds 500_000 ns before dividing by 1_000_000, which rounds to the nearest millisecond, while the comment says it rounds up. If the next scheduled task is less than 0.5 ms away the timeout is 0, so select(...) calls selectNow() and returns. The task is not due yet, so the event loop runs another iteration and does the same again until the deadline is reached. An event loop that has I/O and a pending timer therefore polls the selector in a loop: an application with a timer that fires every ms, 4 event loops and 4000 requests/s used about 3 times the CPU of 4.1, with 8 times as many epoll_wait calls. NioEventLoop in 4.1 rounds up (deadline + 995000) since netty#9799, so the timeout is only 0 if the deadline is within 5 microseconds. The 4.2 NioIoHandler was introduced (netty#13991) with the older rounding. Modification: Add 995_000 instead of 500_000 and adjust the overflow guard to the new bias. Make the method package private so it can be tested. Result: The event loop sleeps in Selector.select(...) until the deadline instead of spinning. Timers can fire up to 1 ms later than before, like in 4.1. The epoll, kqueue and io_uring transports use nanosecond timeouts and are not affected. Assisted-by: Claude Opus 5.5 <[email protected]>
Motivation: NioIoHandler.millisBeforeDeadline(...) adds 500_000 ns before dividing by 1_000_000, which rounds to the nearest millisecond, while the comment says it rounds up. If the next scheduled task is less than 0.5 ms away the timeout is 0, so select(...) calls selectNow() and returns. The task is not due yet, so the event loop runs another iteration and does the same again until the deadline is reached. An event loop that has I/O and a pending timer therefore polls the selector in a loop: an application with a timer that fires every ms, 4 event loops and 4000 requests/s used about 3 times the CPU of 4.1, with 8 times as many epoll_wait calls. NioEventLoop in 4.1 rounds up (deadline + 995000) since #9799, so the timeout is only 0 if the deadline is within 5 microseconds. The 4.2 NioIoHandler was introduced (#13991) with the older rounding. Modification: Add 995_000 instead of 500_000 and adjust the overflow guard to the new bias. Make the method package private so it can be tested. Result: The event loop sleeps in Selector.select(...) until the deadline instead of spinning. Timers can fire up to 1 ms later than before, like in 4.1. The epoll, kqueue and io_uring transports use nanosecond timeouts and are not affected. Assisted-by: Claude Opus 5.5 <[email protected]>
…#18137) (#18141) Auto-port of #18138 to 5.0 Cherry-picked commit: 06518dc --- Motivation: NioIoHandler.millisBeforeDeadline(...) adds 500_000 ns before dividing by 1_000_000, which rounds to the nearest millisecond, while the comment says it rounds up. If the next scheduled task is less than 0.5 ms away the timeout is 0, so select(...) calls selectNow() and returns. The task is not due yet, so the event loop runs another iteration and does the same again until the deadline is reached. An event loop that has I/O and a pending timer therefore polls the selector in a loop: an application with a timer that fires every ms, 4 event loops and 4000 requests/s used about 3 times the CPU of 4.1, with 8 times as many epoll_wait calls. NioEventLoop in 4.1 rounds up (deadline + 995000) since #9799, so the timeout is only 0 if the deadline is within 5 microseconds. The 4.2 NioIoHandler was introduced (#13991) with the older rounding. Modification: Add 995_000 instead of 500_000 and adjust the overflow guard to the new bias. Make the method package private so it can be tested. Result: The event loop sleeps in Selector.select(...) until the deadline instead of spinning. Timers can fire up to 1 ms later than before, like in 4.1. The epoll, kqueue and io_uring transports use nanosecond timeouts and are not affected. Assisted-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Davide D'Alto <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.