Repository: netty/netty
Issue: Setting IORatio to 100


I was reading into netty-transport code and stumble across the ioRatio https://github.com/netty/netty/blob/873988676a2b1bb9cc6e5c1a80e5b27725b1d75c/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java#L515

By the look of it, the smaller the ioRatio, the longer time any non-I/O tasks can spend in the event-loop. For example, given ioTime = 10us

ioRatio of 5 will yield timeout = 190us
ioRatio of 10 will yield timeout = 90us
ioRatio of 50 will yield timeout = 10us
ioRatio of 90 will yield timeout = 1.1111us

According to the documents:
_"Returns the percentage of the desired amount of time spent for I/O in the event loop."_

So it all makes sense.

However, when ioRatio is set to 100, I would expect no non-I/O tasks can be executed. However, the reverse is happening, the code disables the timeout altogether meaning non-I/O tasks can take as long as they like.
Also explained by @Scottmitch in https://github.com/netty/netty/issues/6058#issuecomment-262619885

Should the timeout only be removed when the ioRatio is set to 0, instead of 100?

This make more sense to me:
ioRatio of 0 should disable the timeout
ioRatio of 5 will yield timeout = 190us
ioRatio of 10 will yield timeout = 90us
ioRatio of 50 will yield timeout = 10us
ioRatio of 90 will yield timeout = 1.1111us
ioRatio of 100 will yield timeout = 0 and therefore should not allow non-IO tasks? 










Issue comments:
@lwlee2608 Imho disable all non IO tasks is not going to work as there are situations when Netty need to run these. That said I would say we should most likely just use `99` if 100 is used to not make it behave like `0`.
Ah, all right. I'm not actually suggesting disabling non-IO tasks. But looking at the calculations, don't you think ratio of 0 makes more sense than 100 to disable the timeout?
My logic of thinking is as follows: The larger the ratio, the less amount of time non I/O tasks get. Therefore at the maximum ratio, it does not sound right to get an infinite amount of time.  
But I guess it is too late for the change now. Perhaps we can update to the documentation to clarify on this?
yeah it is too late... prs welcome for docs 
Okay sure :)
The IORatio logic has just been removed in `EpollEventLoop` and I'd assume the intention is to bring `NioEventLoop` in line with this at some point (@normanmaurer correct me if I'm wrong). So it may end up being moot in any case.
@njhill yes... at the end I think that would be the plan. 
oic, I'm still going make the javadoc PR since it's just minimal effort 
ha~
the code show some NON IO Task  must run ,even io Ratio ==100 
 if (ioRatio == 100) {
                    try {
                        if (strategy > 0) {
                            processSelectedKeys();
                        }
                    } finally {
                        // Ensure we always run tasks.
                        ranTasks = runAllTasks();
                    }
                }

Pull request review comments:

Patch that resolved the issue:
diff --git a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java
index e4eb8019de4..8dd7609b41a 100644
--- a/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java
+++ b/transport/src/main/java/io/netty/channel/nio/NioEventLoop.java
@@ -344,8 +344,10 @@ public int getIoRatio() {
     }
 
     /**
-     * Sets the percentage of the desired amount of time spent for I/O in the event loop.  The default value is
-     * {@code 50}, which means the event loop will try to spend the same amount of time for I/O as for non-I/O tasks.
+     * Sets the percentage of the desired amount of time spent for I/O in the event loop. Value range from 1-100.
+     * The default value is {@code 50}, which means the event loop will try to spend the same amount of time for I/O
+     * as for non-I/O tasks. The lower the number the more time can be spent on non-I/O tasks. If value set to
+     * {@code 100}, this feature will be disabled and event loop will not attempt to balance I/O and non-I/O tasks.
      */
     public void setIoRatio(int ioRatio) {
         if (ioRatio <= 0 || ioRatio > 100) {


Test patch: