You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2007/03/12 21:37:23 UTC
svn commit: r517384 -
/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Author: fhanik
Date: Mon Mar 12 13:37:22 2007
New Revision: 517384
URL: http://svn.apache.org/viewvc?view=rev&rev=517384
Log:
Added in the skeleton for fairness logic, currently the tests for fairness are coming out extremely fair, could it be that the Selector.selectedKeys() sorts the keys properly?
Anyway, to implement a scheduler, I can use the "fairness" numbers added in here. Won't do it until I deem it necessary.
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=517384&r1=517383&r2=517384
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Mar 12 13:37:22 2007
@@ -47,6 +47,7 @@
import org.apache.tomcat.util.res.StringManager;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.CountDownLatch;
+import java.util.Comparator;
/**
* NIO tailored thread pool, providing the following services:
@@ -1385,7 +1386,8 @@
}//for
}
}
-
+
+// ----------------------------------------------------- Key Attachment Class
public static class KeyAttachment {
public KeyAttachment() {
@@ -1400,6 +1402,7 @@
timeout = -1;
error = false;
fairness = 0;
+ lastRegistered = 0;
}
public void reset() {
@@ -1435,6 +1438,9 @@
public int getFairness() { return fairness; }
public void setFairness(int f) { fairness = f;}
public void incFairness() { fairness++; }
+ public long getLastRegistered() { return lastRegistered; };
+ public void setLastRegistered(long reg) { lastRegistered = reg; }
+
protected Object mutex = new Object();
protected long lastAccess = -1;
protected boolean currentAccess = false;
@@ -1444,6 +1450,28 @@
protected NioChannel channel = null;
protected CountDownLatch latch = null;
protected int fairness = 0;
+ protected long lastRegistered = 0;
+ }
+// ----------------------------------------------------- Key Fairness Comparator
+ public static class KeyFairnessComparator implements Comparator<KeyAttachment> {
+ public int compare(KeyAttachment ka1, KeyAttachment ka2) {
+ long lr1 = ka1.getLastRegistered();
+ long lr2 = ka2.getLastRegistered();
+ int f1 = ka1.getFairness();
+ int f2 = ka2.getFairness();
+ if ( f1 == f2 ) {
+ if ( lr1 == lr2 ) return 0;
+ //earlier objects have priorioty
+ else return lr1<lr2?-1:1;
+ } else {
+ //higher fairness means earlier in the queue
+ //as fairness count means how many times the poller has skipped
+ //this socket, and the socket has been ready, there just hasn't
+ //been any worker thread available to handle it
+ return ka1.getFairness()>ka2.getFairness()?-1:1;
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org