Repository navigation
Limit the task run per EventLoop tick via a timeout - #14557
Conversation
Motivation: We should better allow to limit the number of tasks that are run per EventLoop tick via a timeout. This timeout can be adjusted by -Dio.netty.eventLoop.maxTaskProcessingDurationPerRun Modifications: Change property name and set default to 1 second. Result: Fixes #14165
|
/cc @dreamlike-ocean |
|
Replaces #14542 |
|
I have another question. Perhaps we could provide a |
| } | ||
| runAllTasks(maxTasksPerRun); | ||
| // Now run all tasks for the maximum configured amount of time before trying to run IO again. | ||
| runAllTasks(maxTaskDurationPerRun); |
There was a problem hiding this comment.
this is a best effect (soft limit), not a hard limit too, I'm not sure the property name
There was a problem hiding this comment.
I am open for better naming.
If we want we can add a constructor parameter for it... But I wanted to keep it simple for now. |
| // TODO: Is this a sensible default ? | ||
| protected static final int DEFAULT_MAX_TASKS_PER_RUN = Math.max(1, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskPerRun", 1024 * 4)); | ||
| protected static final long DEFAULT_MAX_TASKS_PER_RUN_NS = TimeUnit.MILLISECONDS.toNanos(Math.max(10, |
There was a problem hiding this comment.
Let's use 100 ms which is the default CFS period (see https://docs.kernel.org/scheduler/sched-bwc.html)
There was a problem hiding this comment.
@franz1981 do you think this is enough ? I just wonder if this might let tasks grow.
There was a problem hiding this comment.
@franz1981 Do you want to use 100 ms for the minimum quantum, or for the maximum? When I first saw your comment I thought you meant maximum quantum, so as to improve responsiveness in case we get more I/O work while working on the tasks, but on second reading I realize it's not fully clear which one you mean.
There was a problem hiding this comment.
Max :) Sorry i haven't explained properly
| protected static final int DEFAULT_MAX_TASKS_PER_RUN = Math.max(1, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskPerRun", 1024 * 4)); | ||
| protected static final long DEFAULT_MAX_TASKS_PER_RUN_NS = TimeUnit.MILLISECONDS.toNanos(Math.max(10, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskProcessingDurationPerRun", 1000))); |
There was a problem hiding this comment.
io.netty.eventLoop.maxTaskProcessingDurationPerRunSoftLimit what about
There was a problem hiding this comment.
In operating system lingo I think this is called a quantum, so it could also be io.netty.eventLoop.maxTaskProcessingQuantumSoftLimit, but He-Pin's suggestion is also fine.
There was a problem hiding this comment.
Can we include the units in the name of the property to avoid confusion and incorrect units? io.netty.eventLoop.maxTaskProcessingQuantumNsSoftLimit
There was a problem hiding this comment.
+1 to @Scottmitch's suggestion of including units in the name although the units look like their in ms and typically the units are at the end. I'd personally go with io.netty.eventLoop.maxTaskProcessingQuantumMs but don't have strong opinions other than including the units.
| protected static final int DEFAULT_MAX_TASKS_PER_RUN = Math.max(1, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskPerRun", 1024 * 4)); | ||
| protected static final long DEFAULT_MAX_TASKS_PER_RUN_NS = TimeUnit.MILLISECONDS.toNanos(Math.max(10, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskProcessingDurationPerRun", 1000))); |
There was a problem hiding this comment.
Can we include the units in the name of the property to avoid confusion and incorrect units? io.netty.eventLoop.maxTaskProcessingQuantumNsSoftLimit
chrisvest
left a comment
There was a problem hiding this comment.
There are some good suggestions from others I'd also like to see, but I'll pre-approve here.
| // TODO: Is this a sensible default ? | ||
| protected static final int DEFAULT_MAX_TASKS_PER_RUN = Math.max(1, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskPerRun", 1024 * 4)); | ||
| protected static final long DEFAULT_MAX_TASK_PROCESSING_QUANTUM_NS= TimeUnit.MILLISECONDS.toNanos(Math.max(100, |
| // TODO: Is this a sensible default ? | ||
| protected static final int DEFAULT_MAX_TASKS_PER_RUN = Math.max(1, | ||
| SystemPropertyUtil.getInt("io.netty.eventLoop.maxTaskPerRun", 1024 * 4)); | ||
| private static final long DEFAULT_MAX_TASK_PROCESSING_QUANTUM_NS = TimeUnit.MILLISECONDS.toNanos(Math.max(100, |
There was a problem hiding this comment.
Yeah, in CFS this should be the target latency within a process should get its guaranteed fair schedule/chance to run IIRC.
And here, have a similarish meaning i.e. I/O will get its chance to run after this, although with a delay (our tasks are not preemptive).
TBH what CFS does is to update via a timer (the OS tick rate) the virtual time of the task running on CPU, guaranteed a min granularity time to run on the CPU or eventually perform a different decision if there are more.
…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:
We should better allow to limit the number of tasks that are run per EventLoop tick via a timeout. This timeout can be adjusted by -Dio.netty.eventLoop.maxTaskProcessingQuantumMs
Modifications:
Change property name and set default to 1 second.
Result:
Fixes #14165