Skip to content

Commit

Permalink
[finagle-netty4] Expose a knob to control io-ratio in EpollEventLoop
Browse files Browse the repository at this point in the history
Problem
We can't control how much time netty spends processing i/o events compared to other work

Solution
Introduce a knob that allows us to do this

Differential Revision: https://phabricator.twitter.biz/D1175405
  • Loading branch information
mbezoyan authored and jenkins committed Oct 8, 2024
1 parent 3468c99 commit 93f8679
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,27 @@ private object WorkerEventLoop {
)
}

def make(executor: Executor, numWorkers: Int): EventLoopGroup = {
def make(executor: Executor, numWorkers: Int, ioRatio: Int = 50): EventLoopGroup = {
workerPoolSize.addAndGet(numWorkers)
val result =
if (useNativeEpoll() && Epoll.isAvailable) new EpollEventLoopGroup(numWorkers, executor)
else new NioEventLoopGroup(numWorkers, executor)
if (useNativeEpoll() && Epoll.isAvailable) {
val group = new EpollEventLoopGroup(numWorkers, executor)
group.setIoRatio(ioRatio)
group
} else {
new NioEventLoopGroup(numWorkers, executor)
}

eventLoopGroups.add(result)

result
}

lazy val Global: EventLoopGroup = make(
Executors.newCachedThreadPool(new BlockingTimeTrackingThreadFactory(mkNettyThreadFactory())),
numWorkers()
executor = Executors.newCachedThreadPool(
new BlockingTimeTrackingThreadFactory(mkNettyThreadFactory())
),
numWorkers = numWorkers(),
ioRatio = ioRatio()
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.twitter.finagle.netty4

import com.twitter.app.GlobalFlag

/**
* Flag for defining the percentage of the desired amount of time spent for I/O in the child event
* loops. The default value is 50, which means the event loop will try to spend the same amount of
* time for I/O as for non-I/O tasks.
*
* {{
* -com.twitter.finagle.netty4.ioRatio=50
* }}
*
*/
object ioRatio
extends GlobalFlag(
50,
"Sets the percentage of the desired amount of time spent for I/O in the child event loops. " +
"The default value is 50, which means the event loop will try to spend the same amount of " +
"time for I/O as for non-I/O tasks."
)

0 comments on commit 93f8679

Please sign in to comment.