Search in sources :

Example 6 with Tracer

use of org.honu.util.Tracer in project Honu by jboulon.

the class MessageSender method run.

public void run() {
    TChunk chunk = null;
    long timeOut = DEFAULT_POLL_TIMEOUT;
    long curr = 0l;
    while (running || (chunkQueue.size() != 0)) {
        try {
            curr = System.currentTimeMillis();
            if (shutDownNow()) {
                logApp.info("[==HONU==] Honu message sender [" + Thread.currentThread().getId() + "] ShutdownNow");
                break;
            }
            if (curr >= nextStatPeriod) {
                kv.startMessage("HonuSenderStats");
                kv.addKeyValue("chunkCount", chunkCount);
                kv.addKeyValue("lineCount", lineCount);
                kv.addKeyValue("exceptionCount", exceptionCount);
                kv.addKeyValue("period", statFrequency);
                log.info(kv.generateMessage());
                // Keep System.out for debug purpose
                if (log.isDebugEnabled()) {
                    System.out.println(Thread.currentThread().getId() + " - " + new java.util.Date() + " - Chunk sent:" + chunkCount + " - lines:" + lineCount + " - in: 1 min+" + (curr - nextStatPeriod) + " ms");
                }
                lineCount = 0;
                chunkCount = 0;
                exceptionCount = 0;
                nextStatPeriod = System.currentTimeMillis() + statFrequency;
            }
            chunk = chunkQueue.poll(timeOut, TimeUnit.MILLISECONDS);
            // increment sleep time up to maxPollTimeOut
            if (chunk == null) {
                if (timeOut < MAX_POLL_TIMEOUT) {
                    timeOut += DEFAULT_POLL_TIMEOUT;
                }
                continue;
            }
            timeOut = DEFAULT_POLL_TIMEOUT;
            Tracer t = Tracer.startNewTracer("honu.client.sendChunk");
            try {
                (new Tracer("honu.client.chunkQueueSize [chunks, not msec]", chunkQueue.size())).logTracer();
                (new Tracer("honu.client." + chunk.getApplication() + ".chunkQueueSize [chunks, not msec]", chunkQueue.size())).logTracer();
            } catch (Exception ignored) {
            }
            if (System.currentTimeMillis() > leaseTs) {
                logApp.info("Time for lease renewal");
                closeConnection();
            }
            sendChunk(chunk);
            if (t != null) {
                t.stopAndLogTracer();
            }
            chunkCount++;
            lineCount += chunk.getLogEventsSize();
            Thread.yield();
        } catch (Throwable e) {
            logApp.warn("Error in main loop", e);
        }
    }
    if (messageManager != null) {
        messageManager.senderShutdownCallback();
    }
    logApp.info("[==HONU==] Honu message sender [" + Thread.currentThread().getId() + "] shutdown completed, messageQueue:" + chunkQueue.size());
}
Also used : TChunk(org.honu.thrift.TChunk) Tracer(org.honu.util.Tracer)

Aggregations

Tracer (org.honu.util.Tracer)6 TChunk (org.honu.thrift.TChunk)3 ChukwaArchiveKey (org.apache.hadoop.chukwa.ChukwaArchiveKey)2 Chunk (org.apache.hadoop.chukwa.Chunk)2 Result (org.honu.thrift.Result)2 File (java.io.File)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 ChunkBuilder (org.apache.hadoop.chukwa.ChunkBuilder)1 ChunkImpl (org.apache.hadoop.chukwa.ChunkImpl)1 WriterException (org.apache.hadoop.chukwa.datacollection.writer.WriterException)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 SequenceFile (org.apache.hadoop.io.SequenceFile)1 TException (org.apache.thrift.TException)1