Search in sources :

Example 1 with AgentDigestMarshaller

use of com.tdunning.math.stats.AgentDigest.AgentDigestMarshaller in project java by wavefrontHQ.

the class PushAgent method startHistogramListeners.

protected void startHistogramListeners(Iterator<String> ports, Decoder<String> decoder, PointHandler pointHandler, TapeDeck<List<String>> receiveDeck, String listenerBinType, int flushSecs, int fanout, boolean memoryCacheEnabled, File baseDirectory, Long accumulatorSize, int avgKeyBytes, int avgDigestBytes, short compression) {
    // Accumulator
    MapLoader<HistogramKey, AgentDigest, HistogramKeyMarshaller, AgentDigestMarshaller> mapLoader = new MapLoader<>(HistogramKey.class, AgentDigest.class, accumulatorSize, avgKeyBytes, avgDigestBytes, HistogramKeyMarshaller.get(), AgentDigestMarshaller.get(), persistAccumulator);
    File accumulationFile = new File(baseDirectory, "accumulator." + listenerBinType);
    ChronicleMap<HistogramKey, AgentDigest> accumulator = mapLoader.get(accumulationFile);
    histogramExecutor.scheduleWithFixedDelay(() -> {
        // warn if accumulator is more than 1.5x the original size, as ChronicleMap starts losing efficiency
        if (accumulator.size() > accumulatorSize * 1.5) {
            logger.warning("Histogram " + listenerBinType + " accumulator size (" + accumulator.size() + ") is much higher than configured size (" + accumulatorSize + "), proxy may experience performance issues or crash!");
        }
    }, 10, 10, TimeUnit.SECONDS);
    AccumulationCache cachedAccumulator = new AccumulationCache(accumulator, (memoryCacheEnabled ? accumulatorSize : 0), null);
    // Schedule write-backs
    histogramExecutor.scheduleWithFixedDelay(cachedAccumulator.getResolveTask(), histogramAccumulatorResolveInterval, histogramAccumulatorResolveInterval, TimeUnit.MILLISECONDS);
    PointHandlerDispatcher dispatcher = new PointHandlerDispatcher(cachedAccumulator, pointHandler, histogramAccumulatorFlushMaxBatchSize < 0 ? null : histogramAccumulatorFlushMaxBatchSize);
    histogramExecutor.scheduleWithFixedDelay(dispatcher, histogramAccumulatorFlushInterval, histogramAccumulatorFlushInterval, TimeUnit.MILLISECONDS);
    // gracefully shutdown persisted accumulator (ChronicleMap) on proxy exit
    shutdownTasks.add(() -> {
        try {
            logger.fine("Flushing in-flight histogram accumulator digests: " + listenerBinType);
            cachedAccumulator.getResolveTask().run();
            logger.fine("Shutting down histogram accumulator cache: " + listenerBinType);
            accumulator.close();
        } catch (Throwable t) {
            logger.log(Level.SEVERE, "Error flushing " + listenerBinType + " accumulator, possibly unclean shutdown: ", t);
        }
    });
    ports.forEachRemaining(port -> {
        startHistogramListener(port, decoder, pointHandler, cachedAccumulator, baseDirectory, (listenerBinType.equals("minute") ? Utils.Granularity.MINUTE : (listenerBinType.equals("hour") ? Utils.Granularity.HOUR : Utils.Granularity.DAY)), receiveDeck, TimeUnit.SECONDS.toMillis(flushSecs), fanout, compression);
        logger.info("listening on port: " + port + " for histogram samples, accumulating to the " + listenerBinType);
    });
}
Also used : HistogramKey(com.wavefront.agent.histogram.Utils.HistogramKey) AgentDigestMarshaller(com.tdunning.math.stats.AgentDigest.AgentDigestMarshaller) AccumulationCache(com.wavefront.agent.histogram.accumulator.AccumulationCache) MapLoader(com.wavefront.agent.histogram.MapLoader) PointHandlerDispatcher(com.wavefront.agent.histogram.PointHandlerDispatcher) AgentDigest(com.tdunning.math.stats.AgentDigest) HistogramKeyMarshaller(com.wavefront.agent.histogram.Utils.HistogramKeyMarshaller) File(java.io.File)

Aggregations

AgentDigest (com.tdunning.math.stats.AgentDigest)1 AgentDigestMarshaller (com.tdunning.math.stats.AgentDigest.AgentDigestMarshaller)1 MapLoader (com.wavefront.agent.histogram.MapLoader)1 PointHandlerDispatcher (com.wavefront.agent.histogram.PointHandlerDispatcher)1 HistogramKey (com.wavefront.agent.histogram.Utils.HistogramKey)1 HistogramKeyMarshaller (com.wavefront.agent.histogram.Utils.HistogramKeyMarshaller)1 AccumulationCache (com.wavefront.agent.histogram.accumulator.AccumulationCache)1 File (java.io.File)1