Skip to content

Commit

Permalink
Allow to set IoRatio to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer committed Feb 12, 2014
1 parent 4dc337a commit 0ad029b
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions transport/src/main/java/io/netty/channel/nio/NioEventLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public int getIoRatio() {
* {@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.
*/
public void setIoRatio(int ioRatio) {
if (ioRatio <= 0 || ioRatio >= 100) {
throw new IllegalArgumentException("ioRatio: " + ioRatio + " (expected: 0 < ioRatio < 100)");
if (ioRatio <= 0 || ioRatio > 100) {
throw new IllegalArgumentException("ioRatio: " + ioRatio + " (expected: 0 < ioRatio < 101)");
}
this.ioRatio = ioRatio;
}
Expand Down Expand Up @@ -339,18 +339,19 @@ protected void run() {
}

cancelledKeys = 0;

final long ioStartTime = System.nanoTime();
needsToSelectAgain = false;
if (selectedKeys != null) {
processSelectedKeysOptimized(selectedKeys.flip());
final int ioRatio = this.ioRatio;
if (ioRatio == 100) {
processSelectedKeys();
runAllTasks();
} else {
processSelectedKeysPlain(selector.selectedKeys());
}
final long ioTime = System.nanoTime() - ioStartTime;
final long ioStartTime = System.nanoTime();

final int ioRatio = this.ioRatio;
runAllTasks(ioTime * (100 - ioRatio) / ioRatio);
processSelectedKeys();

final long ioTime = System.nanoTime() - ioStartTime;
runAllTasks(ioTime * (100 - ioRatio) / ioRatio);
}

if (isShuttingDown()) {
closeAll();
Expand All @@ -372,6 +373,14 @@ protected void run() {
}
}

private void processSelectedKeys() {
if (selectedKeys != null) {
processSelectedKeysOptimized(selectedKeys.flip());
} else {
processSelectedKeysPlain(selector.selectedKeys());
}
}

@Override
protected void cleanup() {
try {
Expand Down

0 comments on commit 0ad029b

Please sign in to comment.