Search in sources :

Example 1 with SharedResourcesBroker

use of org.apache.gobblin.broker.iface.SharedResourcesBroker 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)

Example 2 with SharedResourcesBroker

use of org.apache.gobblin.broker.iface.SharedResourcesBroker in project incubator-gobblin by apache.

the class DataPublisherFactoryTest method testGetNonThreadSafePublisher.

@Test
public void testGetNonThreadSafePublisher() throws IOException {
    SharedResourcesBroker broker = SharedResourcesBrokerFactory.<SimpleScopeType>createDefaultTopLevelBroker(ConfigFactory.empty(), SimpleScopeType.GLOBAL.defaultScopeInstance());
    DataPublisher publisher1 = DataPublisherFactory.get(TestNonThreadsafeDataPublisher.class.getName(), null, broker);
    DataPublisher publisher2 = DataPublisherFactory.get(TestNonThreadsafeDataPublisher.class.getName(), null, broker);
    // should get different publishers
    Assert.assertNotEquals(publisher1, publisher2);
    // Check capabilities
    Assert.assertTrue(publisher1.supportsCapability(DataPublisher.REUSABLE, Collections.EMPTY_MAP));
    Assert.assertFalse(publisher1.supportsCapability(Capability.THREADSAFE, Collections.EMPTY_MAP));
}
Also used : SharedResourcesBroker(org.apache.gobblin.broker.iface.SharedResourcesBroker) SimpleScopeType(org.apache.gobblin.broker.SimpleScopeType) Test(org.testng.annotations.Test)

Example 3 with SharedResourcesBroker

use of org.apache.gobblin.broker.iface.SharedResourcesBroker in project incubator-gobblin by apache.

the class DataPublisherFactoryTest method testMultiThreadedGetNonThreadSafePublisher.

@Test()
public void testMultiThreadedGetNonThreadSafePublisher() throws InterruptedException, ExecutionException, IOException {
    SharedResourcesBroker broker = SharedResourcesBrokerFactory.<SimpleScopeType>createDefaultTopLevelBroker(ConfigFactory.empty(), SimpleScopeType.GLOBAL.defaultScopeInstance());
    ExecutorService service = Executors.newFixedThreadPool(40);
    List<Future<?>> futures = new ArrayList<>();
    for (int i = 0; i < 100000; i++) {
        futures.add(service.submit(new GetNonThreadSafePublisher(broker)));
    }
    for (Future f : futures) {
        f.get();
    }
    service.shutdown();
    service.awaitTermination(100, TimeUnit.SECONDS);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) SharedResourcesBroker(org.apache.gobblin.broker.iface.SharedResourcesBroker) SimpleScopeType(org.apache.gobblin.broker.SimpleScopeType) Test(org.testng.annotations.Test)

Example 4 with SharedResourcesBroker

use of org.apache.gobblin.broker.iface.SharedResourcesBroker in project incubator-gobblin by apache.

the class DefaultGobblinBrokerTest method testExplicitBinding.

@Test
public void testExplicitBinding() throws Exception {
    Config config = ConfigFactory.empty();
    SharedResourcesBrokerImpl<SimpleScopeType> topBroker = SharedResourcesBrokerFactory.createDefaultTopLevelBroker(config, SimpleScopeType.GLOBAL.defaultScopeInstance());
    SharedResourceFactory<Long, EmptyKey, SimpleScopeType> factory = new SharedResourceFactory<Long, EmptyKey, SimpleScopeType>() {

        @Override
        public String getName() {
            return "myTestFactory";
        }

        @Override
        public SharedResourceFactoryResponse<Long> createResource(SharedResourcesBroker<SimpleScopeType> broker, ScopedConfigView<SimpleScopeType, EmptyKey> config) throws NotConfiguredException {
            throw new UnsupportedOperationException();
        }

        @Override
        public SimpleScopeType getAutoScope(SharedResourcesBroker<SimpleScopeType> broker, ConfigView<SimpleScopeType, EmptyKey> config) {
            return broker.selfScope().getType();
        }
    };
    topBroker.bindSharedResourceAtScope(factory, new EmptyKey(), SimpleScopeType.GLOBAL, 10l);
    Assert.assertEquals(topBroker.getSharedResource(factory, new EmptyKey()), new Long(10));
}
Also used : SharedResourceFactory(org.apache.gobblin.broker.iface.SharedResourceFactory) ConfigView(org.apache.gobblin.broker.iface.ConfigView) ScopedConfigView(org.apache.gobblin.broker.iface.ScopedConfigView) Config(com.typesafe.config.Config) ScopedConfigView(org.apache.gobblin.broker.iface.ScopedConfigView) SharedResourcesBroker(org.apache.gobblin.broker.iface.SharedResourcesBroker) Test(org.testng.annotations.Test)

Aggregations

SharedResourcesBroker (org.apache.gobblin.broker.iface.SharedResourcesBroker)4 Test (org.testng.annotations.Test)3 ExecutorService (java.util.concurrent.ExecutorService)2 Future (java.util.concurrent.Future)2 SimpleScopeType (org.apache.gobblin.broker.SimpleScopeType)2 Config (com.typesafe.config.Config)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 ExecutionException (java.util.concurrent.ExecutionException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 CommandLine (org.apache.commons.cli.CommandLine)1 ConfigView (org.apache.gobblin.broker.iface.ConfigView)1 ScopedConfigView (org.apache.gobblin.broker.iface.ScopedConfigView)1 SharedResourceFactory (org.apache.gobblin.broker.iface.SharedResourceFactory)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