svn commit: r388500 - /tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java

2006-03-24 Thread remm
Author: remm
Date: Fri Mar 24 04:37:27 2006
New Revision: 388500

URL: http://svn.apache.org/viewcvs?rev=388500view=rev
Log:
- As suggested by Peter, replace the (synced) Stack with a specialized unsynced 
stack.

Modified:

tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java

Modified: 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: 
http://svn.apache.org/viewcvs/tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=388500r1=388499r2=388500view=diff
==
--- 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java 
(original)
+++ 
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java 
Fri Mar 24 04:37:27 2006
@@ -19,7 +19,6 @@
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Stack;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -109,10 +108,9 @@
 
 
 /**
- * Available processors.
+ * Available workers.
  */
-// FIXME: Stack is synced, which makes it a non optimal choice
-protected Stack workers = new Stack();
+protected WorkerStack workers = null;
 
 
 /**
@@ -510,7 +508,7 @@
 
 if (initialized)
 return;
-
+
 // Create the root APR memory pool
 rootPool = Pool.create(0);
 // Create the pool for the server socket
@@ -625,6 +623,9 @@
 running = true;
 paused = false;
 
+// Create worker collection
+workers = new WorkerStack(maxThreads);
+
 // Start acceptor thread
 acceptorThread = new Thread(new Acceptor(), getName() + 
-Acceptor);
 acceptorThread.setPriority(threadPriority);
@@ -808,7 +809,7 @@
 synchronized (workers) {
 if (workers.size()  0) {
 curThreadsBusy++;
-return ((Worker) workers.pop());
+return (workers.pop());
 }
 if ((maxThreads  0)  (curThreads  maxThreads)) {
 curThreadsBusy++;
@@ -1516,5 +1517,60 @@
 public boolean process(long socket);
 }
 
+
+// - WorkerStack Inner 
Class
+
+
+public class WorkerStack {
+
+protected Worker[] workers = null;
+protected int end = 0;
+
+public WorkerStack(int size) {
+workers = new Worker[size];
+}
+
+/** 
+ * Put the object into the queue.
+ * 
+ * @param   object  the object to be appended to the queue (first 
element). 
+ */
+public void push(Worker worker) {
+workers[end++] = worker;
+}
+
+/**
+ * Get the first object out of the queue. Return null if the queue
+ * is empty. 
+ */
+public Worker pop() {
+if (end  0) {
+return workers[--end];
+}
+return null;
+}
+
+/**
+ * Get the first object out of the queue, Return null if the queue
+ * is empty.
+ */
+public Worker peek() {
+return workers[end];
+}
+
+/**
+ * Is the queue empty?
+ */
+public boolean isEmpty() {
+return (end == 0);
+}
+
+/**
+ * How many elements are there in this queue?
+ */
+public int size() {
+return (end);
+}
+}
 
 }



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: svn commit: r388500 - /tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java

2006-03-24 Thread Peter Rossbach
Cool catch  = Use simple data structure, with fine performance  
impact. :-)

Peter

Am 24.03.2006 um 13:37 schrieb [EMAIL PROTECTED]:


Author: remm
Date: Fri Mar 24 04:37:27 2006
New Revision: 388500

URL: http://svn.apache.org/viewcvs?rev=388500view=rev
Log:
- As suggested by Peter, replace the (synced) Stack with a  
specialized unsynced stack.


Modified:
tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/ 
AprEndpoint.java


Modified: tomcat/connectors/trunk/util/java/org/apache/tomcat/util/ 
net/AprEndpoint.java
URL: http://svn.apache.org/viewcvs/tomcat/connectors/trunk/util/ 
java/org/apache/tomcat/util/net/AprEndpoint.java? 
rev=388500r1=388499r2=388500view=diff
== 

--- tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/ 
AprEndpoint.java (original)
+++ tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/ 
AprEndpoint.java Fri Mar 24 04:37:27 2006

@@ -19,7 +19,6 @@
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Stack;

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -109,10 +108,9 @@


 /**
- * Available processors.
+ * Available workers.
  */
-// FIXME: Stack is synced, which makes it a non optimal choice
-protected Stack workers = new Stack();
+protected WorkerStack workers = null;


 /**
@@ -510,7 +508,7 @@

 if (initialized)
 return;
-
+
 // Create the root APR memory pool
 rootPool = Pool.create(0);
 // Create the pool for the server socket
@@ -625,6 +623,9 @@
 running = true;
 paused = false;

+// Create worker collection
+workers = new WorkerStack(maxThreads);
+
 // Start acceptor thread
 acceptorThread = new Thread(new Acceptor(), getName()  
+ -Acceptor);

 acceptorThread.setPriority(threadPriority);
@@ -808,7 +809,7 @@
 synchronized (workers) {
 if (workers.size()  0) {
 curThreadsBusy++;
-return ((Worker) workers.pop());
+return (workers.pop());
 }
 if ((maxThreads  0)  (curThreads  maxThreads)) {
 curThreadsBusy++;
@@ -1516,5 +1517,60 @@
 public boolean process(long socket);
 }

+
+// -  
WorkerStack Inner Class

+
+
+public class WorkerStack {
+
+protected Worker[] workers = null;
+protected int end = 0;
+
+public WorkerStack(int size) {
+workers = new Worker[size];
+}
+
+/**
+ * Put the object into the queue.
+ *
+ * @param   object  the object to be appended to the  
queue (first element).

+ */
+public void push(Worker worker) {
+workers[end++] = worker;
+}
+
+/**
+ * Get the first object out of the queue. Return null if  
the queue

+ * is empty.
+ */
+public Worker pop() {
+if (end  0) {
+return workers[--end];
+}
+return null;
+}
+
+/**
+ * Get the first object out of the queue, Return null if  
the queue

+ * is empty.
+ */
+public Worker peek() {
+return workers[end];
+}
+
+/**
+ * Is the queue empty?
+ */
+public boolean isEmpty() {
+return (end == 0);
+}
+
+/**
+ * How many elements are there in this queue?
+ */
+public int size() {
+return (end);
+}
+}

 }



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: svn commit: r388500 - /tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java

2006-03-24 Thread Remy Maucherat

Peter Rossbach wrote:

Cool catch  = Use simple data structure, with fine performance impact. :-)


Believe it or not, but it's just a little bit faster than the stack 
(which has the same behavior, except with syncs).


Rémy

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: svn commit: r388500 - /tomcat/connectors/trunk/util/java/org/apache/tomcat/util/net/AprEndpoint.java

2006-03-24 Thread Filip Hanik - Dev Lists

Remy Maucherat wrote:

Peter Rossbach wrote:
Cool catch  = Use simple data structure, with fine performance 
impact. :-)


Believe it or not, but it's just a little bit faster than the stack 
(which has the same behavior, except with syncs).
you can only tell true performance improvement on machines with more 
than one CPU, say 4/8/32 CPU machines, sync vs using thread safe non 
sync the difference can be huge.


Filip

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]