Example usage for com.google.common.util.concurrent RateLimiter create

List of usage examples for com.google.common.util.concurrent RateLimiter create

Introduction

In this page you can find the example usage for com.google.common.util.concurrent RateLimiter create.

Prototype



public static RateLimiter create(double permitsPerSecond) 

Source Link

Document

Creates a RateLimiter with the specified stable throughput, given as "permits per second" (commonly referred to as QPS, queries per second).

Usage

From source file:org.opendaylight.controller.cluster.datastore.utils.TransactionRateLimiter.java

public TransactionRateLimiter(ActorContext actorContext) {
    this.actorContext = actorContext;
    this.commitTimeoutInSeconds = actorContext.getDatastoreContext()
            .getShardTransactionCommitTimeoutInSeconds();
    this.dataStoreName = actorContext.getDataStoreName();
    this.txRateLimiter = RateLimiter
            .create(actorContext.getDatastoreContext().getTransactionCreationInitialRateLimit());
}

From source file:com.twitter.distributedlog.benchmark.utils.ShiftableRateLimiter.java

public ShiftableRateLimiter(double initialRate, double maxRate, double changeRate, long changeInterval,
        TimeUnit changeIntervalUnit) {
    this.initialRate = initialRate;
    this.maxRate = maxRate;
    this.changeRate = changeRate;
    this.nextRate = initialRate;
    this.rateLimiter = RateLimiter.create(initialRate);
    this.executor = Executors.newSingleThreadScheduledExecutor();
    this.executor.scheduleAtFixedRate(this, changeInterval, changeInterval, changeIntervalUnit);
}

From source file:org.eclipse.buildship.ui.view.execution.UpdateExecutionPageJob.java

@Override
protected IStatus run(IProgressMonitor monitor) {
    RateLimiter rateLimiter = RateLimiter.create(MAX_UPDATES_PER_SECOND);
    while (this.running || !this.queue.isEmpty()) {
        rateLimiter.acquire();// w  w w.  ja  va  2  s . co m

        List<ProgressEvent> events = Lists.newArrayList();
        this.queue.drainTo(events);

        Display display = PlatformUI.getWorkbench().getDisplay();
        if (!display.isDisposed()) {
            display.syncExec(new UpdateExecutionPageContent(this.page, events));
        }
    }

    return Status.OK_STATUS;
}

From source file:org.apache.distributedlog.benchmark.utils.ShiftableRateLimiter.java

public ShiftableRateLimiter(double initialRate, double maxRate, double changeRate, long changeInterval,
        TimeUnit changeIntervalUnit) {
    this.initialRate = initialRate;
    this.maxRate = maxRate;
    this.changeRate = changeRate;
    this.nextRate = initialRate;
    this.changeInterval = changeInterval;
    this.changeIntervalUnit = changeIntervalUnit;
    this.rateLimiter = RateLimiter.create(initialRate);
    this.executor = Executors.newSingleThreadScheduledExecutor();
    this.executor.scheduleAtFixedRate(this, changeInterval, changeInterval, changeIntervalUnit);
}

From source file:com.iflytek.edu.cloud.frame.web.filter.HttpRequestRateLimiterFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    String value = filterConfig.getInitParameter("permitsPerSecond");
    int permitsPerSecond = DEFAULT_PERMITS_PER_SECOND;
    if (StringUtils.hasText(value))
        permitsPerSecond = Integer.valueOf(value);

    limiter = RateLimiter.create(permitsPerSecond);

    LOGGER.info("?http{}", permitsPerSecond);
}

From source file:com.amazonaws.services.dynamodbv2.online.index.TableRWRateLimiter.java

public TableRWRateLimiter(double readWriteIOPSCapacityUnits, double readWriteIOPSPercent, int numOfTasks) {
    this.readWriteIOPSCapacityUnits = readWriteIOPSCapacityUnits;
    this.readWriteIOPSPercent = readWriteIOPSPercent;
    this.numOfTasks = numOfTasks;
    this.accumulatedReadWritePermits = 0;
    double rateLimit = getRateLimit();
    rateLimiter = RateLimiter.create(rateLimit);
}

From source file:com.spotify.helios.master.reaper.RateLimitedService.java

RateLimitedService(final double permitsPerSecond, final long initialDelay, final long delay,
        final TimeUnit timeUnit) {
    this.rateLimiter = RateLimiter.create(permitsPerSecond);
    this.initialDelay = initialDelay;
    this.delay = delay;
    this.timeUnit = timeUnit;
}

From source file:uk.co.caprica.rottentomatoes.service.jaxrs.JaxrsRottenTomatoesService.java

/**
 *
 *
 * @param apiKey// w w  w.ja v a  2 s  . co  m
 * @param requestsPerSecondLimit
 */
public JaxrsRottenTomatoesService(String apiKey, int requestsPerSecondLimit) {
    this.apiKey = apiKey;
    client = ClientBuilder.newClient();
    rateLimiter = RateLimiter.create(requestsPerSecondLimit);
}

From source file:name.nirav.mp.service.analytics.EntityExtractionService.java

public EntityExtractionService(OpenCalaisConfig config, PredictionDB db) {
    this.config = config;
    this.calaisConfig = new CalaisConfig();
    this.calaisConfig.set(CalaisConfig.ConnParam.READ_TIMEOUT, config.readTimeout);
    this.calaisConfig.set(CalaisConfig.ConnParam.CONNECT_TIMEOUT, config.readTimeout);
    this.db = db;
    this.client = new CalaisRestClient(config.licenseKey);
    this.rateLimiter = RateLimiter.create(4);
    Timer timer = new Timer("Calais-ban-reset");
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            LocalDateTime now = LocalDateTime.now();
            if (now.getHour() >= 23) {
                LOG.info("It is close to midnight {}, resetting callCount", now.getHour());
                callCount = 0;/*from  w  w w  .  j a v  a2 s .co m*/
            }
        }
    }, 1000, TimeUnit.MINUTES.toMillis(30));
}

From source file:com.google.cloud.trace.sdk.RateLimiterTraceEnablingPolicy.java

@Override
public void initFromProperties(Properties props) {
    String rateStr = props.getProperty(getClass().getName() + ".ratePerSecond");
    if (rateStr != null) {
        try {/*  w w w.  j a v a2 s .  co  m*/
            double rate = Double.parseDouble(rateStr);
            this.limiter = RateLimiter.create(rate);
        } catch (NumberFormatException nfe) {
            logger.log(Level.WARNING, "Found non-numeric rate in the properties (" + rateStr + ")");
        }
    }
}