Search in sources :

Example 1 with MockRequester

use of org.apache.gobblin.util.limiter.MockRequester in project incubator-gobblin by apache.

the class LocalStressTest method main.

public static void main(String[] args) throws Exception {
    CommandLine cli = StressTestUtils.parseCommandLine(OPTIONS, args);
    int stressorThreads = Integer.parseInt(cli.getOptionValue(STRESSOR_THREADS.getOpt(), Integer.toString(DEFAULT_STRESSOR_THREADS)));
    int processorThreads = Integer.parseInt(cli.getOptionValue(PROCESSOR_THREADS.getOpt(), Integer.toString(DEFAULT_PROCESSOR_THREADS)));
    int artificialLatency = Integer.parseInt(cli.getOptionValue(ARTIFICIAL_LATENCY.getOpt(), Integer.toString(DEFAULT_ARTIFICIAL_LATENCY)));
    long targetQps = Integer.parseInt(cli.getOptionValue(QPS.getOpt(), Integer.toString(DEFAULT_TARGET_QPS)));
    Configuration configuration = new Configuration();
    StressTestUtils.populateConfigFromCli(configuration, cli);
    String resourceLimited = LocalStressTest.class.getSimpleName();
    Map<String, String> configMap = Maps.newHashMap();
    ThrottlingPolicyFactory factory = new ThrottlingPolicyFactory();
    SharedLimiterKey res1key = new SharedLimiterKey(resourceLimited);
    configMap.put(BrokerConfigurationKeyGenerator.generateKey(factory, res1key, null, ThrottlingPolicyFactory.POLICY_KEY), QPSPolicy.FACTORY_ALIAS);
    configMap.put(BrokerConfigurationKeyGenerator.generateKey(factory, res1key, null, QPSPolicy.QPS), Long.toString(targetQps));
    ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig();
    guiceServletConfig.initialize(ConfigFactory.parseMap(configMap));
    LimiterServerResource limiterServer = guiceServletConfig.getInjector().getInstance(LimiterServerResource.class);
    RateComputingLimiterContainer limiterContainer = new RateComputingLimiterContainer();
    Class<? extends Stressor> stressorClass = configuration.getClass(StressTestUtils.STRESSOR_CLASS, StressTestUtils.DEFAULT_STRESSOR_CLASS, Stressor.class);
    ExecutorService executorService = Executors.newFixedThreadPool(stressorThreads);
    SharedResourcesBroker broker = guiceServletConfig.getInjector().getInstance(Key.get(SharedResourcesBroker.class, Names.named(LimiterServerResource.BROKER_INJECT_NAME)));
    ThrottlingPolicy policy = (ThrottlingPolicy) broker.getSharedResource(new ThrottlingPolicyFactory(), new SharedLimiterKey(resourceLimited));
    ScheduledExecutorService reportingThread = Executors.newSingleThreadScheduledExecutor();
    reportingThread.scheduleAtFixedRate(new Reporter(limiterContainer, policy), 0, 15, TimeUnit.SECONDS);
    Queue<Future<?>> futures = new LinkedList<>();
    MockRequester requester = new MockRequester(limiterServer, artificialLatency, processorThreads);
    requester.start();
    for (int i = 0; i < stressorThreads; i++) {
        RestliServiceBasedLimiter restliLimiter = RestliServiceBasedLimiter.builder().resourceLimited(resourceLimited).requestSender(requester).serviceIdentifier("stressor" + i).build();
        Stressor stressor = stressorClass.newInstance();
        stressor.configure(configuration);
        futures.add(executorService.submit(new StressorRunner(limiterContainer.decorateLimiter(restliLimiter), stressor)));
    }
    int stressorFailures = 0;
    for (Future<?> future : futures) {
        try {
            future.get();
        } catch (ExecutionException ee) {
            stressorFailures++;
        }
    }
    requester.stop();
    executorService.shutdownNow();
    if (stressorFailures > 0) {
        log.error("There were " + stressorFailures + " failed stressor threads.");
    }
    System.exit(stressorFailures);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SharedResourcesBroker(org.apache.gobblin.broker.iface.SharedResourcesBroker) MockRequester(org.apache.gobblin.util.limiter.MockRequester) Stressor(org.apache.gobblin.util.limiter.stressTest.Stressor) RateComputingLimiterContainer(org.apache.gobblin.util.limiter.stressTest.RateComputingLimiterContainer) SharedLimiterKey(org.apache.gobblin.util.limiter.broker.SharedLimiterKey) ExecutionException(java.util.concurrent.ExecutionException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) CommandLine(org.apache.commons.cli.CommandLine) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) RestliServiceBasedLimiter(org.apache.gobblin.util.limiter.RestliServiceBasedLimiter)

Aggregations

LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 CommandLine (org.apache.commons.cli.CommandLine)1 SharedResourcesBroker (org.apache.gobblin.broker.iface.SharedResourcesBroker)1 MockRequester (org.apache.gobblin.util.limiter.MockRequester)1 RestliServiceBasedLimiter (org.apache.gobblin.util.limiter.RestliServiceBasedLimiter)1 SharedLimiterKey (org.apache.gobblin.util.limiter.broker.SharedLimiterKey)1 RateComputingLimiterContainer (org.apache.gobblin.util.limiter.stressTest.RateComputingLimiterContainer)1 Stressor (org.apache.gobblin.util.limiter.stressTest.Stressor)1 Configuration (org.apache.hadoop.conf.Configuration)1