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 2008/11/26 04:54:39 UTC
svn commit: r720728 -
/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Author: fhanik
Date: Tue Nov 25 19:54:38 2008
New Revision: 720728
URL: http://svn.apache.org/viewvc?rev=720728&view=rev
Log:
Add the ability to configure multiple pollers and default them to number of CPUs
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=720728&r1=720727&r2=720728&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Tue Nov 25 19:54:38 2008
@@ -490,7 +490,7 @@
/**
* Poller thread count.
*/
- protected int pollerThreadCount = 1;
+ protected int pollerThreadCount = Runtime.getRuntime().availableProcessors();
public void setPollerThreadCount(int pollerThreadCount) { this.pollerThreadCount = pollerThreadCount; }
public int getPollerThreadCount() { return pollerThreadCount; }
@@ -500,9 +500,15 @@
/**
* The socket poller.
*/
- protected Poller poller = null;
+ protected Poller[] pollers = null;
+ protected AtomicInteger pollerRotater = new AtomicInteger(0);
+ /**
+ * Return an available poller in true round robin fashion
+ * @return
+ */
public Poller getPoller0() {
- return poller;
+ int idx = Math.abs(pollerRotater.incrementAndGet()) % pollers.length;
+ return pollers[idx];
}
/**
@@ -695,10 +701,14 @@
* Number of keepalive sockets.
*/
public int getKeepAliveCount() {
- if (poller == null) {
+ if (pollers == null) {
return 0;
} else {
- return poller.selector.keys().size();
+ int sum = 0;
+ for (int i=0; i<pollers.length; i++) {
+ sum += pollers[i].selector.keys().size();
+ }
+ return sum;
}
}
@@ -845,12 +855,15 @@
workers = new WorkerStack(maxThreads);
}
- // Start poller thread
- poller = new Poller();
- Thread pollerThread = new Thread(poller, getName() + "-ClientPoller");
- pollerThread.setPriority(threadPriority);
- pollerThread.setDaemon(true);
- pollerThread.start();
+ // Start poller threads
+ pollers = new Poller[getPollerThreadCount()];
+ for (int i=0; i<pollers.length; i++) {
+ pollers[i] = new Poller();
+ Thread pollerThread = new Thread(pollers[i], getName() + "-ClientPoller-"+i);
+ pollerThread.setPriority(threadPriority);
+ pollerThread.setDaemon(true);
+ pollerThread.start();
+ }
// Start acceptor threads
for (int i = 0; i < acceptorThreadCount; i++) {
@@ -892,8 +905,11 @@
if (running) {
running = false;
unlockAccept();
- poller.destroy();
- poller = null;
+ for (int i=0; pollers!=null && i<pollers.length; i++) {
+ if (pollers[i]==null) continue;
+ pollers[i].destroy();
+ pollers[i] = null;
+ }
}
eventCache.clear();
keyCache.clear();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org