diff --git a/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/WorkerEventLoop.scala b/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/WorkerEventLoop.scala index debeff3bba..c42c08cbf7 100644 --- a/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/WorkerEventLoop.scala +++ b/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/WorkerEventLoop.scala @@ -61,11 +61,16 @@ 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) @@ -73,7 +78,10 @@ private object WorkerEventLoop { } lazy val Global: EventLoopGroup = make( - Executors.newCachedThreadPool(new BlockingTimeTrackingThreadFactory(mkNettyThreadFactory())), - numWorkers() + executor = Executors.newCachedThreadPool( + new BlockingTimeTrackingThreadFactory(mkNettyThreadFactory()) + ), + numWorkers = numWorkers(), + ioRatio = ioRatio() ) } diff --git a/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/ioRatio.scala b/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/ioRatio.scala new file mode 100644 index 0000000000..d20580f396 --- /dev/null +++ b/finagle-netty4/src/main/scala/com/twitter/finagle/netty4/ioRatio.scala @@ -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." + )