Search in sources :

Example 1 with RecyclableRateLimiter

use of com.google.common.util.concurrent.RecyclableRateLimiter in project java by wavefrontHQ.

the class QueuedAgentServiceTest method testSetup.

@Before
public void testSetup() throws IOException {
    mockAgentAPI = EasyMock.createMock(WavefrontAPI.class);
    newAgentId = UUID.randomUUID();
    int retryThreads = 1;
    QueuedAgentService.setSplitBatchSize(splitBatchSize);
    queuedAgentService = new QueuedAgentService(mockAgentAPI, "unitTestBuffer", retryThreads, Executors.newScheduledThreadPool(retryThreads + 1, new ThreadFactory() {

        private AtomicLong counter = new AtomicLong();

        @Override
        public Thread newThread(Runnable r) {
            Thread toReturn = new Thread(r);
            toReturn.setName("unit test submission worker: " + counter.getAndIncrement());
            return toReturn;
        }
    }), true, newAgentId, false, (RecyclableRateLimiter) null);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) WavefrontAPI(com.wavefront.api.WavefrontAPI) RecyclableRateLimiter(com.google.common.util.concurrent.RecyclableRateLimiter) Before(org.junit.Before)

Example 2 with RecyclableRateLimiter

use of com.google.common.util.concurrent.RecyclableRateLimiter 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 3 with RecyclableRateLimiter

use of com.google.common.util.concurrent.RecyclableRateLimiter 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)3 EntityProperties (com.wavefront.agent.data.EntityProperties)2 WavefrontAPI (com.wavefront.api.WavefrontAPI)1 ReportableEntityType (com.wavefront.data.ReportableEntityType)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Before (org.junit.Before)1