User: juhalindfors
  Date: 01/04/18 13:36:17

  Modified:    src/main/org/jboss/ejb/plugins MetricsInterceptor.java
  Log:
  Attempts to deal with message congestion a little better.
  
  Revision  Changes    Path
  1.9       +36 -12    jboss/src/main/org/jboss/ejb/plugins/MetricsInterceptor.java
  
  Index: MetricsInterceptor.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/ejb/plugins/MetricsInterceptor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MetricsInterceptor.java   2001/04/18 15:25:51     1.8
  +++ MetricsInterceptor.java   2001/04/18 20:36:17     1.9
  @@ -55,7 +55,9 @@
       private String applicationName        = "<undefined>";
       /** Bean name in the container.                     */ 
       private String beanName               = "<undefined>";
  -
  +    /** Publisher thread.                               */
  +    private Thread publisher              = null;
  +    
       /**
        * Message queue for the outgoing JMS messages. This list is accessed
        * by the interceptor when adding new messages, and by the publisher
  @@ -124,12 +126,18 @@
            * wonder if container method callback order is documented somewhere, it 
should be.. 
            */
            
  -        Thread thread = new Thread(new Publisher());
  -        thread.setName("Metrics Publisher Thread for " + beanName + ".");
  -        thread.setDaemon(true);
  -        thread.start();
  +        publisher = new Thread(new Publisher());
  +        publisher.setName("Metrics Publisher Thread for " + beanName + ".");
  +        publisher.setDaemon(true);
  +        publisher.start();
      }
   
  +   /**
  +    * Kills the publisher thread.
  +    */
  +   public void destroy() {
  +        publisher.interrupt();    
  +   }
      
       // Private --------------------------------------------------------
       
  @@ -140,7 +148,7 @@
        * @param   begin   invocation begin time in ms
        * @param   end     invocation end time in ms
        */
  -    private void addEntry(MethodInvocation mi, long begin, long end) {
  +    private final void addEntry(MethodInvocation mi, long begin, long end) {
           
           /* this gets called by the interceptor */
           
  @@ -172,7 +180,7 @@
               msg.setStringProperty(BEAN, beanName);
               msg.setObjectProperty(METHOD, method);    
               msg.setLongProperty(TIME, time);
  -            
  +
               if (txID != -1) 
                   msg.setStringProperty("ID",  String.valueOf(txID));
                           
  @@ -219,7 +227,7 @@
           public void run() {
       
               try {
  -                final boolean IS_TRANSACTED    = false;
  +                final boolean IS_TRANSACTED    = true;
                   final int     ACKNOWLEDGE_MODE = Session.DUPS_OK_ACKNOWLEDGE;
                  
                   // lookup the connection factory and topic and create a JMS session
  @@ -243,9 +251,14 @@
                   while (running) {
   
                       Object[] array;
  -
  +                    long sleepTime = delay;
  +                    
                       try {
  -                        Thread.sleep(delay);
  +                        Thread.sleep(sleepTime);
  +                        
  +                        // measure message processing cost and try to deal
  +                        // with congestion
  +                        long begin = System.currentTimeMillis();
                           
                           // synchronized during the copy... the interceptor will
                           // have to wait til done
  @@ -265,7 +278,18 @@
                                             );
                                             
                               pub.publish(msg);
  -                        }                                          
  +                        }
  +                        
  +                        // try to deal with congestion a little better, alot of
  +                        // small messages fast will kill JBossMQ performance, this 
is
  +                        // a temp fix to group many messages into one operation
  +                        try {session.commit();} catch (Exception e) {}
  +
  +                        // stop the clock and reduce the work time from our
  +                        // resting time
  +                        long end = System.currentTimeMillis();
  +                  
  +                        sleepTime = delay - (end - begin);
                       }
                       catch (InterruptedException e) {
                           // kill this thread
  @@ -291,7 +315,7 @@
        *
        * @see #msgQueue
        */
  -    private class Entry {
  +    private final class Entry {
        
          int  id = -1;
          long time;
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to