Search in sources :

Example 21 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project flink by apache.

the class TaskManagerServices method fromConfiguration.

// --------------------------------------------------------------------------------------------
//  Static factory methods for task manager services
// --------------------------------------------------------------------------------------------
/**
	 * Creates and returns the task manager services.
	 *
	 * @param resourceID resource ID of the task manager
	 * @param taskManagerServicesConfiguration task manager configuration
	 * @return task manager components
	 * @throws Exception
	 */
public static TaskManagerServices fromConfiguration(TaskManagerServicesConfiguration taskManagerServicesConfiguration, ResourceID resourceID) throws Exception {
    // pre-start checks
    checkTempDirs(taskManagerServicesConfiguration.getTmpDirPaths());
    final NetworkEnvironment network = createNetworkEnvironment(taskManagerServicesConfiguration);
    network.start();
    final TaskManagerLocation taskManagerLocation = new TaskManagerLocation(resourceID, taskManagerServicesConfiguration.getTaskManagerAddress(), network.getConnectionManager().getDataPort());
    // this call has to happen strictly after the network stack has been initialized
    final MemoryManager memoryManager = createMemoryManager(taskManagerServicesConfiguration);
    // start the I/O manager, it will create some temp directories.
    final IOManager ioManager = new IOManagerAsync(taskManagerServicesConfiguration.getTmpDirPaths());
    final MetricRegistry metricRegistry = new MetricRegistry(taskManagerServicesConfiguration.getMetricRegistryConfiguration());
    final TaskManagerMetricGroup taskManagerMetricGroup = new TaskManagerMetricGroup(metricRegistry, taskManagerLocation.getHostname(), taskManagerLocation.getResourceID().toString());
    // Initialize the TM metrics
    TaskExecutorMetricsInitializer.instantiateStatusMetrics(taskManagerMetricGroup, network);
    final BroadcastVariableManager broadcastVariableManager = new BroadcastVariableManager();
    final FileCache fileCache = new FileCache(taskManagerServicesConfiguration.getTmpDirPaths());
    final List<ResourceProfile> resourceProfiles = new ArrayList<>(taskManagerServicesConfiguration.getNumberOfSlots());
    for (int i = 0; i < taskManagerServicesConfiguration.getNumberOfSlots(); i++) {
        resourceProfiles.add(new ResourceProfile(1.0, 42));
    }
    final TimerService<AllocationID> timerService = new TimerService<>(new ScheduledThreadPoolExecutor(1), taskManagerServicesConfiguration.getTimerServiceShutdownTimeout());
    final TaskSlotTable taskSlotTable = new TaskSlotTable(resourceProfiles, timerService);
    final JobManagerTable jobManagerTable = new JobManagerTable();
    final JobLeaderService jobLeaderService = new JobLeaderService(taskManagerLocation);
    return new TaskManagerServices(taskManagerLocation, memoryManager, ioManager, network, metricRegistry, taskManagerMetricGroup, broadcastVariableManager, fileCache, taskSlotTable, jobManagerTable, jobLeaderService);
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) IOManager(org.apache.flink.runtime.io.disk.iomanager.IOManager) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) MetricRegistry(org.apache.flink.runtime.metrics.MetricRegistry) TaskManagerMetricGroup(org.apache.flink.runtime.metrics.groups.TaskManagerMetricGroup) AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) ArrayList(java.util.ArrayList) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) TimerService(org.apache.flink.runtime.taskexecutor.slot.TimerService) FileCache(org.apache.flink.runtime.filecache.FileCache) IOManagerAsync(org.apache.flink.runtime.io.disk.iomanager.IOManagerAsync) TaskSlotTable(org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable) BroadcastVariableManager(org.apache.flink.runtime.broadcast.BroadcastVariableManager) NetworkEnvironment(org.apache.flink.runtime.io.network.NetworkEnvironment)

Example 22 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project qi4j-sdk by Qi4j.

the class SchedulerMixin method activateService.

@Override
public void activateService() throws Exception {
    // Handle configuration defaults
    SchedulerConfiguration configuration = config.get();
    Integer workersCount = configuration.workersCount().get();
    Integer workQueueSize = configuration.workQueueSize().get();
    if (workersCount == null) {
        workersCount = DEFAULT_WORKERS_COUNT;
        LOGGER.debug("Workers count absent from configuration, falled back to default: {} workers", DEFAULT_WORKERS_COUNT);
    }
    if (workQueueSize == null) {
        workQueueSize = DEFAULT_WORKQUEUE_SIZE;
        LOGGER.debug("WorkQueue size absent from configuration, falled back to default: {}", DEFAULT_WORKQUEUE_SIZE);
    }
    int corePoolSize = 2;
    if (workersCount > 4) {
        corePoolSize = workersCount / 4;
    }
    // Throws IllegalArgument if corePoolSize or keepAliveTime less than zero, or if workersCount less than or equal to zero, or if corePoolSize greater than workersCount.
    taskExecutor = new ThreadPoolExecutor(corePoolSize, workersCount, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(workQueueSize), threadFactory, rejectionHandler);
    taskExecutor.prestartAllCoreThreads();
    managementExecutor = new ScheduledThreadPoolExecutor(2, threadFactory, rejectionHandler);
    loadSchedules();
    LOGGER.debug("Activated");
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 23 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project hbase by apache.

the class TestHBaseFsckReplicas method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.getConfiguration().set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, MasterSyncObserver.class.getName());
    conf.setInt("hbase.regionserver.handler.count", 2);
    conf.setInt("hbase.regionserver.metahandler.count", 30);
    conf.setInt("hbase.htable.threads.max", POOL_SIZE);
    conf.setInt("hbase.hconnection.threads.max", 2 * POOL_SIZE);
    conf.setInt("hbase.hbck.close.timeout", 2 * REGION_ONLINE_TIMEOUT);
    conf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 8 * REGION_ONLINE_TIMEOUT);
    TEST_UTIL.startMiniCluster(3);
    tableExecutorService = new ThreadPoolExecutor(1, POOL_SIZE, 60, TimeUnit.SECONDS, new SynchronousQueue<>(), Threads.newDaemonThreadFactory("testhbck"));
    hbfsckExecutorService = new ScheduledThreadPoolExecutor(POOL_SIZE);
    AssignmentManager assignmentManager = TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager();
    regionStates = assignmentManager.getRegionStates();
    connection = (ClusterConnection) TEST_UTIL.getConnection();
    admin = connection.getAdmin();
    admin.setBalancerRunning(false, true);
    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.META_TABLE_NAME);
    TEST_UTIL.waitUntilAllRegionsAssigned(TableName.NAMESPACE_TABLE_NAME);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SynchronousQueue(java.util.concurrent.SynchronousQueue) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) BeforeClass(org.junit.BeforeClass)

Example 24 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project hadoop by apache.

the class TestShutdownThreadsHelper method testShutdownThreadPool.

@Test
public void testShutdownThreadPool() throws InterruptedException {
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    executor.execute(sampleRunnable);
    boolean ret = ShutdownThreadsHelper.shutdownExecutorService(executor);
    boolean isTerminated = executor.isTerminated();
    assertEquals("Incorrect return value", ret, isTerminated);
    assertTrue("ExecutorService is not shutdown", isTerminated);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Test(org.junit.Test)

Example 25 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project hadoop by apache.

the class SchedulerService method init.

@Override
public void init() throws ServiceException {
    int threads = getServiceConfig().getInt(CONF_THREADS, 5);
    scheduler = new ScheduledThreadPoolExecutor(threads);
    LOG.debug("Scheduler started");
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)298 Test (org.junit.Test)52 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)51 ThreadFactory (java.util.concurrent.ThreadFactory)36 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)35 ExecutorService (java.util.concurrent.ExecutorService)34 Before (org.junit.Before)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 Test (org.testng.annotations.Test)19 IOException (java.io.IOException)16 CountDownLatch (java.util.concurrent.CountDownLatch)16 ArrayList (java.util.ArrayList)15 List (java.util.List)15 HashMap (java.util.HashMap)12 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)11 File (java.io.File)11 ScheduledFuture (java.util.concurrent.ScheduledFuture)10 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)8 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)8