FileDocCategorySizeDatePackage
ThroughputInterceptor.javaAPI DocApache Tomcat 6.0.144743Fri Jul 20 04:20:32 BST 2007org.apache.catalina.tribes.group.interceptors

ThroughputInterceptor

public class ThroughputInterceptor extends org.apache.catalina.tribes.group.ChannelInterceptorBase
author
Filip Hanik
version
1.0

Fields Summary
protected static org.apache.juli.logging.Log
log
double
mbTx
double
mbAppTx
double
mbRx
double
timeTx
double
lastCnt
AtomicLong
msgTxCnt
AtomicLong
msgRxCnt
AtomicLong
msgTxErr
int
interval
AtomicInteger
access
long
txStart
long
rxStart
DecimalFormat
df
Constructors Summary
Methods Summary
public intgetInterval()

        return interval;
    
public voidmessageReceived(org.apache.catalina.tribes.ChannelMessage msg)

        if ( rxStart == 0 ) rxStart = System.currentTimeMillis();
        long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength());
        mbRx += ((double)bytes)/(1024d*1024d);
        msgRxCnt.addAndGet(1);
        if ( msgRxCnt.get() % interval == 0 ) report(timeTx);
        super.messageReceived(msg);
        
    
public voidreport(double timeTx)

        StringBuffer buf = new StringBuffer("ThroughputInterceptor Report[\n\tTx Msg:");
        buf.append(msgTxCnt).append(" messages\n\tSent:");
        buf.append(df.format(mbTx));
        buf.append(" MB (total)\n\tSent:");
        buf.append(df.format(mbAppTx));
        buf.append(" MB (application)\n\tTime:");
        buf.append(df.format(timeTx));
        buf.append(" seconds\n\tTx Speed:");
        buf.append(df.format(mbTx/timeTx));
        buf.append(" MB/sec (total)\n\tTxSpeed:");
        buf.append(df.format(mbAppTx/timeTx));
        buf.append(" MB/sec (application)\n\tError Msg:");
        buf.append(msgTxErr).append("\n\tRx Msg:");
        buf.append(msgRxCnt);
        buf.append(" messages\n\tRx Speed:");
        buf.append(df.format(mbRx/((double)((System.currentTimeMillis()-rxStart)/1000))));
        buf.append(" MB/sec (since 1st msg)\n\tReceived:");
        buf.append(df.format(mbRx)).append(" MB]\n");
        if ( log.isInfoEnabled() ) log.info(buf);
    
public voidsendMessage(org.apache.catalina.tribes.Member[] destination, org.apache.catalina.tribes.ChannelMessage msg, org.apache.catalina.tribes.group.InterceptorPayload payload)



              
        if ( access.addAndGet(1) == 1 ) txStart = System.currentTimeMillis();
        long bytes = XByteBuffer.getDataPackageLength(((ChannelData)msg).getDataPackageLength());
        try {
            super.sendMessage(destination, msg, payload);
        }catch ( ChannelException x ) {
            msgTxErr.addAndGet(1);
            access.addAndGet(-1);
            throw x;
        } 
        mbTx += ((double)(bytes*destination.length))/(1024d*1024d);
        mbAppTx += ((double)(bytes))/(1024d*1024d);
        if ( access.addAndGet(-1) == 0 ) {
            long stop = System.currentTimeMillis();
            timeTx += ( (double) (stop - txStart)) / 1000d;
            if ((msgTxCnt.get() / interval) >= lastCnt) {
                lastCnt++;
                report(timeTx);
            }
        }
        msgTxCnt.addAndGet(1);
    
public voidsetInterval(int interval)

        this.interval = interval;