fhanik      2004/01/12 16:07:18

  Modified:    modules/cluster/src/share/org/apache/catalina/cluster/mcast
                        McastServiceImpl.java
               modules/cluster/src/share/org/apache/catalina/cluster/session
                        DeltaManager.java DeltaRequest.java
                        ReplicationStream.java
               modules/cluster/src/share/org/apache/catalina/cluster/tcp
                        AsyncSocketSender.java SimpleTcpCluster.java
                        SocketSender.java ThreadPool.java
  Log:
  Performance optimization:
  1. When you know what class loader to use, use it, huge performance improvement
  2. Use the Externalizable interface to control what gets serialized
  Name the threads so that we can differentiate them better when profiling
  
  Revision  Changes    Path
  1.6       +10 -4     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java
  
  Index: McastServiceImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/mcast/McastServiceImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- McastServiceImpl.java     18 Dec 2003 04:20:14 -0000      1.5
  +++ McastServiceImpl.java     13 Jan 2004 00:07:18 -0000      1.6
  @@ -246,6 +246,10 @@
   
   
       public class ReceiverThread extends Thread {
  +        public ReceiverThread() {
  +            super();
  +            setName("Cluster-MembershipReceiver");
  +        }
           public void run() {
               while ( doRun ) {
                   try {
  @@ -261,6 +265,8 @@
           long time;
           public SenderThread(long time) {
               this.time = time;
  +            setName("Cluster-MembershipSender");
  +
           }
           public void run() {
               while ( doRun ) {
  
  
  
  1.4       +4 -5      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java
  
  Index: DeltaManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DeltaManager.java 12 Jan 2004 07:50:06 -0000      1.3
  +++ DeltaManager.java 13 Jan 2004 00:07:18 -0000      1.4
  @@ -441,7 +441,6 @@
   
           // Initialize our internal data structures
           //sessions.clear(); //should not do this
  -
           // Open an input stream to the specified pathname, if any
           ByteArrayInputStream fis = null;
           ObjectInputStream ois = null;
  
  
  
  1.3       +74 -10    
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaRequest.java
  
  Index: DeltaRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/DeltaRequest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DeltaRequest.java 12 Jan 2004 07:50:06 -0000      1.2
  +++ DeltaRequest.java 13 Jan 2004 00:07:18 -0000      1.3
  @@ -71,15 +71,15 @@
    * @version 1.0
    */
   
  -import java.util.Vector;
  +import java.util.LinkedList;
   import javax.servlet.http.HttpSession;
  -import java.io.Serializable;
  +import java.io.Externalizable;
   import java.security.Principal;
   import org.apache.catalina.realm.GenericPrincipal;
   import org.apache.catalina.cluster.ClusterSession;
   
   
  -public class DeltaRequest implements Serializable {
  +public class DeltaRequest implements Externalizable {
   
       public static final int TYPE_ATTRIBUTE = 0;
       public static final int TYPE_PRINCIPAL = 1;
  @@ -94,9 +94,13 @@
       public static final String NAME_ISNEW = "__SET__ISNEW__";
   
       private String sessionId;
  -    private Vector actions = new Vector();
  +    private LinkedList actions = new LinkedList();
       private boolean recordAllActions = false;
   
  +    public DeltaRequest() {
  +        
  +    }
  +
       public DeltaRequest(String sessionId, boolean recordAllActions) {
           this.recordAllActions=recordAllActions;
           setSessionId(sessionId);
  @@ -141,7 +145,7 @@
           //we don't send multiple actions across the wire
           if ( !recordAllActions) actions.remove(info);
           //add the action
  -        actions.addElement(info);
  +        actions.addLast(info);
       }
   
       public void execute(ClusterSession session) {
  @@ -194,13 +198,48 @@
       public int getSize() {
           return actions.size();
       }
  +    
  +    public void readExternal(java.io.ObjectInput in ) throws java.io.IOException,
  +    java.lang.ClassNotFoundException {
  +    //sessionId - String
  +    //recordAll - boolean
  +    //size - int
  +    //AttributeInfo - in an array
  +        sessionId = in.readUTF();
  +        recordAllActions = in.readBoolean();
  +        int cnt = in.readInt();
  +        if ( actions == null )
  +            actions = new LinkedList();
  +        else
  +            actions.clear();
  +        for (int i = 0; i < cnt; i++) {
  +            AttributeInfo info = (AttributeInfo)in.readObject();
  +            actions.addLast(info);
  +        }//for
  +    }
  +        
  +
  +
  +    public void writeExternal(java.io.ObjectOutput out ) throws java.io.IOException 
{
  +        //sessionId - String
  +        //recordAll - boolean
  +        //size - int
  +        //AttributeInfo - in an array
  +        out.writeUTF(getSessionId());
  +        out.writeBoolean(recordAllActions);
  +        out.writeInt(getSize());
  +        for ( int i=0; i<getSize(); i++ ) {
  +            AttributeInfo info = (AttributeInfo)actions.get(i);
  +            out.writeObject(info);
  +        }
  +    }
   
  -    public static class AttributeInfo implements java.io.Serializable {
  +    public static class AttributeInfo implements java.io.Externalizable {
           private String name = null;
           private Object value = null;
           private int action;
           private int type;
  -
  +        public AttributeInfo() {}
           public AttributeInfo(int type,
                                int action,
                                String name,
  @@ -235,6 +274,31 @@
               AttributeInfo other =  (AttributeInfo)o;
               return other.getName().equals(this.getName());
           }
  +        
  +        public void readExternal(java.io.ObjectInput in ) throws 
java.io.IOException,
  +            java.lang.ClassNotFoundException {
  +            //type - int
  +            //action - int
  +            //name - String
  +            //value - object
  +            type = in.readInt();
  +            action = in.readInt();
  +            name = in.readUTF();
  +            value = in.readObject();
  +        }
  +
  +        public void writeExternal(java.io.ObjectOutput out) throws java.io.
  +            IOException {
  +            //type - int
  +            //action - int
  +            //name - String
  +            //value - object
  +            out.writeInt(getType());
  +            out.writeInt(getAction());
  +            out.writeUTF(getName());
  +            out.writeObject(getValue());
  +        }
  +
   
       }
   
  
  
  
  1.2       +22 -6     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/ReplicationStream.java
  
  Index: ReplicationStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/session/ReplicationStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReplicationStream.java    19 Feb 2003 20:32:10 -0000      1.1
  +++ ReplicationStream.java    13 Jan 2004 00:07:18 -0000      1.2
  @@ -115,13 +115,29 @@
        */
       public Class resolveClass(ObjectStreamClass classDesc)
           throws ClassNotFoundException, IOException {
  +        String name = classDesc.getName();
  +        boolean tryRepFirst = name.startsWith("org.apache.catalina.cluster");
           try
           {
  -            return (classLoader.loadClass(classDesc.getName()));
  +            if ( tryRepFirst ) return findReplicationClass(name);
  +            else return findWebappClass(name);
           }
           catch ( Exception x )
           {
  -            return getClass().getClassLoader().loadClass(classDesc.getName());
  +            if ( tryRepFirst ) return findWebappClass(name);
  +            else return findReplicationClass(name);
           }
       }
  +    
  +    public Class findReplicationClass(String name)
  +        throws ClassNotFoundException, IOException {
  +        return Class.forName(name, false, getClass().getClassLoader());
  +    }
  +
  +    public Class findWebappClass(String name)
  +        throws ClassNotFoundException, IOException {
  +        return Class.forName(name, false, classLoader);
  +    }
  +
  +
   }
  
  
  
  1.3       +7 -4      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/AsyncSocketSender.java
  
  Index: AsyncSocketSender.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/AsyncSocketSender.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AsyncSocketSender.java    15 Oct 2003 03:21:04 -0000      1.2
  +++ AsyncSocketSender.java    13 Jan 2004 00:07:18 -0000      1.3
  @@ -68,6 +68,7 @@
   import java.io.IOException;
   import org.apache.catalina.cluster.util.SmartQueue;
   public class AsyncSocketSender implements IDataSender {
  +    private static int threadCounter=1;
       private InetAddress address;
       private int port;
       private Socket sc = null;
  @@ -153,8 +154,10 @@
       
       private class QueueThread extends Thread {
           AsyncSocketSender sender;
  +
           public QueueThread(AsyncSocketSender sender) {
               this.sender = sender;
  +            setName("Cluster-AsyncSocketSender-"+(threadCounter++));
           }
           
           public void run() {
  @@ -174,4 +177,4 @@
               }
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.25      +6 -4      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java
  
  Index: SimpleTcpCluster.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SimpleTcpCluster.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- SimpleTcpCluster.java     12 Jan 2004 07:50:07 -0000      1.24
  +++ SimpleTcpCluster.java     13 Jan 2004 00:07:18 -0000      1.25
  @@ -492,6 +492,7 @@
                                               "synchronous".equals(this.
                       replicationMode));
                   Thread t = new Thread(mReplicationListener);
  +                t.setName("Cluster-TcpListener");
                   t.setDaemon(true);
                   t.start();
               } else {
  @@ -503,6 +504,7 @@
                                               this.tcpSelectorTimeout,
                                               
IDataSenderFactory.SYNC_MODE.equals(replicationMode) ||
                                               
IDataSenderFactory.POOLED_SYNC_MODE.equals(replicationMode));
  +                mReplicationListener.setName("Cluster-ReplicationListener");
                   mReplicationListener.setDaemon(true);
                   mReplicationListener.start();
               }
  
  
  
  1.10      +4 -4      
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SocketSender.java
  
  Index: SocketSender.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/SocketSender.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SocketSender.java 9 Jan 2004 23:24:09 -0000       1.9
  +++ SocketSender.java 13 Jan 2004 00:07:18 -0000      1.10
  @@ -85,7 +85,7 @@
       private Socket sc = null;
       private boolean isSocketConnected = false;
       private boolean suspect;
  -    private long ackTimeout = 150*1000;  //15 seconds socket read timeout (for 
acknowledgement)
  +    private long ackTimeout = 15*1000;  //15 seconds socket read timeout (for 
acknowledgement)
       private long keepAliveTimeout = 60*1000; //keep socket open for no more than 
one min
       private int keepAliveMaxRequestCount = 100; //max 100 requests before 
reconnecting
       private long keepAliveConnectTime = 0;
  
  
  
  1.5       +19 -7     
jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ThreadPool.java
  
  Index: ThreadPool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/modules/cluster/src/share/org/apache/catalina/cluster/tcp/ThreadPool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ThreadPool.java   9 Jan 2004 23:24:09 -0000       1.4
  +++ ThreadPool.java   13 Jan 2004 00:07:18 -0000      1.5
  @@ -83,6 +83,7 @@
        */
   
       List idle = new LinkedList();
  +    Object mutex = new Object();
   
       ThreadPool (int poolSize, Class threadClass) throws Exception {
           // fill up the pool with worker threads
  @@ -107,9 +108,19 @@
       {
           WorkerThread worker = null;
   
  -        synchronized (idle) {
  -            if (idle.size() > 0) {
  -                worker = (WorkerThread) idle.remove (0);
  +        
  +        synchronized (mutex) {
  +            while ( worker == null ) {
  +                if (idle.size() > 0) {
  +                    try {
  +                        worker = (WorkerThread) idle.remove(0);
  +                    } catch (java.util.NoSuchElementException x) {
  +                        //this means that there are no available workers
  +                        worker = null;
  +                    }
  +                } else {
  +                    try { mutex.wait(); } catch ( java.lang.InterruptedException x 
) {}
  +                }
               }
           }
   
  @@ -122,8 +133,9 @@
        */
       void returnWorker (WorkerThread worker)
       {
  -        synchronized (idle) {
  +        synchronized (mutex) {
               idle.add (worker);
  +            mutex.notify();
           }
       }
   }
  
  
  

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

Reply via email to