Search in sources :

Example 1 with DefaultMessagingService

use of org.apache.helix.messaging.DefaultMessagingService in project helix by apache.

the class TestResourceThreadpoolSize method TestThreadPoolSizeConfig.

@Test
public void TestThreadPoolSizeConfig() {
    setResourceThreadPoolSize("NextDB", 12);
    _setupTool.addResourceToCluster(CLUSTER_NAME, "NextDB", 64, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "NextDB", 3);
    boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    long taskcount = 0;
    for (int i = 0; i < NODE_NR; i++) {
        DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
        HelixTaskExecutor helixExecutor = svc.getExecutor();
        ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + "NextDB"));
        Assert.assertEquals(12, executor.getMaximumPoolSize());
        taskcount += executor.getCompletedTaskCount();
        Assert.assertTrue(executor.getCompletedTaskCount() > 0);
    }
    Assert.assertEquals(taskcount, 64 * 4);
}
Also used : DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.testng.annotations.Test)

Example 2 with DefaultMessagingService

use of org.apache.helix.messaging.DefaultMessagingService in project helix by apache.

the class TestResourceThreadpoolSize method TestPerStateTransitionTypeThreadPool.

@Test
public void TestPerStateTransitionTypeThreadPool() throws InterruptedException {
    String MASTER_SLAVE = "MasterSlave";
    int customizedPoolSize = 22;
    for (MockParticipantManager participant : _participants) {
        participant.getStateMachineEngine().registerStateModelFactory(MASTER_SLAVE, new TestMasterSlaveStateModelFactory(customizedPoolSize), TEST_FACTORY);
    }
    // add db with customized thread pool
    IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "4").setStateModel(MASTER_SLAVE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", idealState);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", 1);
    Thread.sleep(2000);
    // Verify OFFLINE -> SLAVE and SLAVE -> MASTER have different threadpool size.
    for (int i = 0; i < NODE_NR; i++) {
        DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
        HelixTaskExecutor helixExecutor = svc.getExecutor();
        ThreadPoolExecutor executorOfflineToSlave = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + OFFLINE_TO_SLAVE));
        Assert.assertEquals(customizedPoolSize, executorOfflineToSlave.getMaximumPoolSize());
        ThreadPoolExecutor executorSlaveToMaster = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + SLAVE_TO_MASTER));
        Assert.assertEquals(customizedPoolSize + 5, executorSlaveToMaster.getMaximumPoolSize());
    }
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 3 with DefaultMessagingService

use of org.apache.helix.messaging.DefaultMessagingService in project helix by apache.

the class TestResourceThreadpoolSize method TestCustomizedResourceThreadPool.

@Test
public void TestCustomizedResourceThreadPool() {
    int customizedPoolSize = 7;
    int configuredPoolSize = 9;
    for (MockParticipantManager participant : _participants) {
        participant.getStateMachineEngine().registerStateModelFactory(ONLINE_OFFLINE, new TestOnlineOfflineStateModelFactory(customizedPoolSize, 0), TEST_FACTORY);
    }
    // add db with default thread pool
    _setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 64, STATE_MODEL);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 3);
    // add db with customized thread pool
    IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "2").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", idealState);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", 1);
    // add db with configured pool size
    idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "3").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
    _setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", idealState);
    setResourceThreadPoolSize(WorkflowGenerator.DEFAULT_TGT_DB + "3", configuredPoolSize);
    _setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", 1);
    boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
    Assert.assertTrue(result);
    for (int i = 0; i < NODE_NR; i++) {
        DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
        HelixTaskExecutor helixExecutor = svc.getExecutor();
        ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "1"));
        Assert.assertNull(executor);
        executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "2"));
        Assert.assertEquals(customizedPoolSize, executor.getMaximumPoolSize());
        executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "3"));
        Assert.assertEquals(configuredPoolSize, executor.getMaximumPoolSize());
    }
}
Also used : MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) ClusterStateVerifier(org.apache.helix.tools.ClusterStateVerifier) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 4 with DefaultMessagingService

use of org.apache.helix.messaging.DefaultMessagingService in project helix by apache.

the class TestBatchMessageModeConfigs method verify.

private void verify() {
    DefaultMessagingService svc = (DefaultMessagingService) (_participants[0].getMessagingService());
    HelixTaskExecutor helixExecutor = svc.getExecutor();
    ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._batchMessageExecutorService);
    Assert.assertNotNull(executor);
    Assert.assertTrue(executor.getPoolSize() > 0);
}
Also used : DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 5 with DefaultMessagingService

use of org.apache.helix.messaging.DefaultMessagingService in project helix by apache.

the class TestConfigThreadpoolSize method TestThreadPoolSizeConfig.

@Test
public void TestThreadPoolSizeConfig() {
    String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + 0);
    HelixManager manager = _participants[0];
    ConfigAccessor accessor = manager.getConfigAccessor();
    ConfigScope scope = new ConfigScopeBuilder().forCluster(manager.getClusterName()).forParticipant(instanceName).build();
    accessor.set(scope, "TestMsg." + HelixTaskExecutor.MAX_THREADS, "" + 12);
    scope = new ConfigScopeBuilder().forCluster(manager.getClusterName()).build();
    accessor.set(scope, "TestMsg." + HelixTaskExecutor.MAX_THREADS, "" + 8);
    for (int i = 0; i < NODE_NR; i++) {
        instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        _participants[i].getMessagingService().registerMessageHandlerFactory("TestMsg", new TestMessagingHandlerFactory());
        _participants[i].getMessagingService().registerMessageHandlerFactory("TestMsg2", new TestMessagingHandlerFactory2());
    }
    for (int i = 0; i < NODE_NR; i++) {
        instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
        DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
        HelixTaskExecutor helixExecutor = svc.getExecutor();
        ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get("TestMsg"));
        ThreadPoolExecutor executor2 = (ThreadPoolExecutor) (helixExecutor._executorMap.get("TestMsg2"));
        if (i != 0) {
            Assert.assertEquals(8, executor.getMaximumPoolSize());
        } else {
            Assert.assertEquals(12, executor.getMaximumPoolSize());
        }
        Assert.assertEquals(HelixTaskExecutor.DEFAULT_PARALLEL_TASKS, executor2.getMaximumPoolSize());
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) ConfigScope(org.apache.helix.model.ConfigScope) DefaultMessagingService(org.apache.helix.messaging.DefaultMessagingService) ConfigAccessor(org.apache.helix.ConfigAccessor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConfigScopeBuilder(org.apache.helix.model.builder.ConfigScopeBuilder) Test(org.testng.annotations.Test)

Aggregations

ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)6 DefaultMessagingService (org.apache.helix.messaging.DefaultMessagingService)6 Test (org.testng.annotations.Test)5 IdealState (org.apache.helix.model.IdealState)3 FullAutoModeISBuilder (org.apache.helix.model.builder.FullAutoModeISBuilder)3 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)2 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)2 ConfigAccessor (org.apache.helix.ConfigAccessor)1 HelixManager (org.apache.helix.HelixManager)1 ConfigScope (org.apache.helix.model.ConfigScope)1 ConfigScopeBuilder (org.apache.helix.model.builder.ConfigScopeBuilder)1 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)1 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)1