Search in sources :

Example 1 with EntityProperties

use of com.wavefront.agent.data.EntityProperties in project java by wavefrontHQ.

the class TrafficShapingRateLimitAdjuster method run.

@Override
public void run() {
    for (ReportableEntityType type : ReportableEntityType.values()) {
        EntityProperties props = entityProps.get(type);
        long rate = props.getTotalReceivedRate();
        EvictingRingBuffer<Long> stats = perEntityStats.computeIfAbsent(type, x -> new SynchronizedEvictingRingBuffer<>(windowSeconds));
        if (rate > 0 || stats.size() > 0) {
            stats.add(rate);
            if (stats.size() >= 60) {
                // need at least 1 minute worth of stats to enable the limiter
                RecyclableRateLimiter rateLimiter = props.getRateLimiter();
                adjustRateLimiter(type, stats, rateLimiter);
            }
        }
    }
}
Also used : EntityProperties(com.wavefront.agent.data.EntityProperties) RecyclableRateLimiter(com.google.common.util.concurrent.RecyclableRateLimiter) ReportableEntityType(com.wavefront.data.ReportableEntityType)

Example 2 with EntityProperties

use of com.wavefront.agent.data.EntityProperties in project java by wavefrontHQ.

the class PushAgent method updateRateLimiter.

private void updateRateLimiter(ReportableEntityType entityType, @Nullable Boolean collectorSetsRateLimit, @Nullable Number collectorRateLimit, @Nullable Number globalRateLimit) {
    EntityProperties entityProperties = entityProps.get(entityType);
    RecyclableRateLimiter rateLimiter = entityProperties.getRateLimiter();
    if (rateLimiter != null) {
        if (BooleanUtils.isTrue(collectorSetsRateLimit)) {
            if (collectorRateLimit != null && rateLimiter.getRate() != collectorRateLimit.doubleValue()) {
                rateLimiter.setRate(collectorRateLimit.doubleValue());
                entityProperties.setItemsPerBatch(Math.min(collectorRateLimit.intValue(), entityProperties.getItemsPerBatch()));
                logger.warning(entityType.toCapitalizedString() + " rate limit set to " + collectorRateLimit + entityType.getRateUnit() + " remotely");
            }
        } else {
            double rateLimit = Math.min(entityProperties.getRateLimit(), ObjectUtils.firstNonNull(globalRateLimit, NO_RATE_LIMIT).intValue());
            if (rateLimiter.getRate() != rateLimit) {
                rateLimiter.setRate(rateLimit);
                if (entityProperties.getItemsPerBatchOriginal() > rateLimit) {
                    entityProperties.setItemsPerBatch((int) rateLimit);
                } else {
                    entityProperties.setItemsPerBatch(null);
                }
                if (rateLimit >= NO_RATE_LIMIT) {
                    logger.warning(entityType.toCapitalizedString() + " rate limit is no longer " + "enforced by remote");
                } else {
                    if (proxyCheckinScheduler != null && proxyCheckinScheduler.getSuccessfulCheckinCount() > 1) {
                        // this will skip printing this message upon init
                        logger.warning(entityType.toCapitalizedString() + " rate limit restored to " + rateLimit + entityType.getRateUnit());
                    }
                }
            }
        }
    }
}
Also used : EntityProperties(com.wavefront.agent.data.EntityProperties) RecyclableRateLimiter(com.google.common.util.concurrent.RecyclableRateLimiter)

Aggregations

RecyclableRateLimiter (com.google.common.util.concurrent.RecyclableRateLimiter)2 EntityProperties (com.wavefront.agent.data.EntityProperties)2 ReportableEntityType (com.wavefront.data.ReportableEntityType)1