Example #1
0
        /// <exception cref="System.Exception"/>
        protected override void ServiceStart()
        {
            client.Start();
            ThreadFactory tf = new ThreadFactoryBuilder().SetNameFormat(this.GetType().FullName
                                                                        + " #%d").SetDaemon(true).Build();
            // Start with a default core-pool size and change it dynamically.
            int initSize = Math.Min(InitialThreadPoolSize, maxThreadPoolSize);

            threadPool = new ThreadPoolExecutor(initSize, int.MaxValue, 1, TimeUnit.Hours, new
                                                LinkedBlockingQueue <Runnable>(), tf);
            eventDispatcherThread = new _Thread_125(this);
            // We can increase the pool size only if haven't reached the maximum
            // limit yet.
            // nodes where containers will run at *this* point of time. This is
            // *not* the cluster size and doesn't need to be.
            // Bump up the pool size to idealThreadPoolSize +
            // INITIAL_POOL_SIZE, the later is just a buffer so we are not
            // always increasing the pool-size
            // the events from the queue are handled in parallel with a thread
            // pool
            // TODO: Group launching of multiple containers to a single
            // NodeManager into a single connection
            eventDispatcherThread.SetName("Container  Event Dispatcher");
            eventDispatcherThread.SetDaemon(false);
            eventDispatcherThread.Start();
            base.ServiceStart();
        }
 public void SetUp()
 {
     _queue = MockRepository.GenerateStub<IBlockingQueue<IRunnable>>();
     _runnable = MockRepository.GenerateMock<IRunnable>();
     _callerRunsPolicy = new ThreadPoolExecutor.CallerRunsPolicy();
     _threadPoolExecutor = new ThreadPoolExecutor(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
 /// <summary> 
 /// Obtains and ignores the next task that the <paramref name="executor"/>
 /// would otherwise execute, if one is immediately available,
 /// and then retries execution of task <paramref name="runnable"/>, unless the <paramref name="executor"/>
 /// is shut down, in which case task <paramref name="runnable"/> is instead discarded.
 /// </summary>
 /// <param name="runnable">the <see cref="Spring.Threading.IRunnable"/> task requested to be executed</param>
 /// <param name="executor">the <see cref="Spring.Threading.Execution.ThreadPoolExecutor"/> attempting to execute this task</param>
 public virtual void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
     if (executor.IsShutdown) return;
     IRunnable head;
     executor.Queue.Poll(out head);
     executor.Execute(runnable);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HystrixThreadPoolMetrics"/> class.
 /// </summary>
 /// <param name="threadPoolKey">The key of the parent thread pool.</param>
 /// <param name="threadPool">The <see cref="ThreadPoolExecutor"/> of the parent thread pool.</param>
 /// <param name="properties">The properties of the parent thread pool.</param>
 private HystrixThreadPoolMetrics(HystrixThreadPoolKey threadPoolKey, ThreadPoolExecutor threadPool, IHystrixThreadPoolProperties properties)
 {
     this.threadPoolKey = threadPoolKey;
     this.threadPool    = threadPool;
     this.properties    = properties;
     this.counter       = new HystrixRollingNumber(properties.MetricsRollingStatisticalWindowInMilliseconds, properties.MetricsRollingStatisticalWindowBuckets);
 }
Example #5
0
        public override void performOperationStep(DeploymentOperation operationContext)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.camunda.bpm.container.impl.spi.PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
            PlatformServiceContainer serviceContainer = operationContext.ServiceContainer;

            JobExecutorXml jobExecutorXml = getJobExecutorXml(operationContext);

            int  queueSize     = getQueueSize(jobExecutorXml);
            int  corePoolSize  = getCorePoolSize(jobExecutorXml);
            int  maxPoolSize   = getMaxPoolSize(jobExecutorXml);
            long keepAliveTime = getKeepAliveTime(jobExecutorXml);

            // initialize Queue & Executor services
            BlockingQueue <ThreadStart> threadPoolQueue = new ArrayBlockingQueue <ThreadStart>(queueSize);

            ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, threadPoolQueue);

            threadPoolExecutor.RejectedExecutionHandler = new ThreadPoolExecutor.AbortPolicy();

            // construct the service for the thread pool
            JmxManagedThreadPool managedThreadPool = new JmxManagedThreadPool(threadPoolQueue, threadPoolExecutor);

            // install the service into the container
            serviceContainer.startService(ServiceTypes.BPM_PLATFORM, RuntimeContainerDelegateImpl.SERVICE_NAME_EXECUTOR, managedThreadPool);
        }
        /// <summary>Constructor.</summary>
        /// <param name="numThreads">
        /// -- if less than or equal to 0, then automatically determine the number
        /// of threads. Otherwise, the size of the underlying threadpool.
        /// </param>
        /// <param name="processor"/>
        /// <param name="orderResults">
        /// -- If true, return results in the order submitted. Otherwise, return results
        /// as they become available.
        /// </param>
        public MulticoreWrapper(int numThreads, IThreadsafeProcessor <I, O> processor, bool orderResults)
        {
            // Which id was the last id returned.  Only meaningful in the case
            // of a queue where output order matters.
            //  private final ExecutorCompletionService<Integer> queue;
            nThreads          = numThreads <= 0 ? Runtime.GetRuntime().AvailableProcessors() : numThreads;
            this.orderResults = orderResults;
            outputQueue       = new ConcurrentHashMap <int, O>(2 * nThreads);
            threadPool        = BuildThreadPool(nThreads);
            //    queue = new ExecutorCompletionService<Integer>(threadPool);
            idleProcessors = new ArrayBlockingQueue <int>(nThreads, false);
            callback       = null;
            // Sanity check: Fixed thread pool so prevent timeouts.
            // Default should be false
            threadPool.AllowCoreThreadTimeOut(false);
            threadPool.PrestartAllCoreThreads();
            // Setup the processors, one per thread
            IList <IThreadsafeProcessor <I, O> > procList = new List <IThreadsafeProcessor <I, O> >(nThreads);

            procList.Add(processor);
            idleProcessors.Add(0);
            for (int i = 1; i < nThreads; ++i)
            {
                procList.Add(processor.NewInstance());
                idleProcessors.Add(i);
            }
            processorList = Java.Util.Collections.UnmodifiableList(procList);
        }
Example #7
0
        public virtual void Stop()
        {
            try
            {
                ThrowIfDisposed();
                lock (Lockable)
                {
                    if (State == ThreadState.Running)
                    {
                        State = ThreadState.StopRequested;
                        Cts.Cancel();
                        executor = null;
                        State    = ThreadState.Stopped;
                    }
                }

                AppDomain.CurrentDomain.DomainUnload -= CurrentDomain_DomainUnload;
            }
            catch (Exception exc)
            {
                // ignore. Just make sure stop does not throw.
                Log.Debug("Ignoring error during Stop: {0}", exc);
            }
            Log.Debug("Stopped agent");
        }
Example #8
0
        public FsDatasetCache(FsDatasetImpl dataset)
        {
            this.dataset  = dataset;
            this.maxBytes = dataset.datanode.GetDnConf().GetMaxLockedMemory();
            ThreadFactory workerFactory = new ThreadFactoryBuilder().SetDaemon(true).SetNameFormat
                                              ("FsDatasetCache-%d-" + dataset.ToString()).Build();

            this.usedBytesCount    = new FsDatasetCache.UsedBytesCount(this);
            this.uncachingExecutor = new ThreadPoolExecutor(0, 1, 60, TimeUnit.Seconds, new LinkedBlockingQueue
                                                            <Runnable>(), workerFactory);
            this.uncachingExecutor.AllowCoreThreadTimeOut(true);
            this.deferredUncachingExecutor = new ScheduledThreadPoolExecutor(1, workerFactory
                                                                             );
            this.revocationMs = dataset.datanode.GetConf().GetLong(DFSConfigKeys.DfsDatanodeCacheRevocationTimeoutMs
                                                                   , DFSConfigKeys.DfsDatanodeCacheRevocationTimeoutMsDefault);
            long confRevocationPollingMs = dataset.datanode.GetConf().GetLong(DFSConfigKeys.DfsDatanodeCacheRevocationPollingMs
                                                                              , DFSConfigKeys.DfsDatanodeCacheRevocationPollingMsDefault);
            long minRevocationPollingMs = revocationMs / 2;

            if (minRevocationPollingMs < confRevocationPollingMs)
            {
                throw new RuntimeException("configured value " + confRevocationPollingMs + "for "
                                           + DFSConfigKeys.DfsDatanodeCacheRevocationPollingMs + " is too high.  It must not be more than half of the "
                                           + "value of " + DFSConfigKeys.DfsDatanodeCacheRevocationTimeoutMs + ".  Reconfigure this to "
                                           + minRevocationPollingMs);
            }
            this.revocationPollingMs = confRevocationPollingMs;
        }
Example #9
0
        public void ExecutionContinuesWithOneThreadWhenFactoryFailesToCreateMore()
        {
            var       nRun   = new AtomicInteger(0);
            const int nTasks = 100;

            var failingThreadFactory = MockRepository.GenerateStub <IThreadFactory>();

            failingThreadFactory.Stub(f => f.NewThread(Arg <IRunnable> .Is.NotNull))
            .Do(new Function <IRunnable, Thread>(r => new Thread(r.Run))).Repeat.Once();

            var es = new ThreadPoolExecutor(nTasks, nTasks, Delays.Long,
                                            new LinkedBlockingQueue <IRunnable>(), failingThreadFactory);

            ExecutorService = es;

            for (int k = 0; k < nTasks; ++k)
            {
                es.Execute(() => nRun.IncrementValueAndReturn());
            }
            for (int i = 0; i < 20 && nRun.Value < nTasks; i++)
            {
                Thread.Sleep(Delays.Short);
            }
            Assert.That(es.PoolSize, Is.EqualTo(1));
            Assert.AreEqual(nTasks, nRun.Value);
        }
Example #10
0
        public void ExecuteAllowsResubmitSameTask()
        {
            const int     nTasks   = 1000;
            AtomicInteger nRun     = new AtomicInteger(0);
            IRunnable     runnable = new Runnable(() => nRun.IncrementValueAndReturn());
            var           es       = new ThreadPoolExecutor(1, 30, Delays.Long, new ArrayBlockingQueue <IRunnable>(30));

            ExecutorService = es;
            for (int i = 0; i < nTasks; ++i)
            {
                for (; ;)
                {
                    try
                    {
                        es.Execute(runnable);
                        break;
                    }
                    catch (RejectedExecutionException)
                    {
                    }
                }
            }
            // enough time to run all tasks
            for (int i = 0; i < 20 && nRun.Value < nTasks; i++)
            {
                Thread.Sleep(Delays.Short);
            }
            Assert.AreEqual(nRun.Value, nTasks);
        }
Example #11
0
        public void BeforeAfterExecuteAreCalledWhenExecutingFailedTaks()
        {
            var ex       = new NullReferenceException();
            var runnable = MockRepository.GenerateStub <IRunnable>();

            runnable.Stub(r => r.Run()).Throw(ex);
            var noExceptionFactory = MockRepository.GenerateStub <IThreadFactory>();

            noExceptionFactory.Stub(f => f.NewThread(Arg <IRunnable> .Is.Anything)).Do(
                new Delegates.Function <Thread, IRunnable>(
                    r => new Thread(() => { try { r.Run(); } catch (NullReferenceException) { } })));
            var es = Mockery.GeneratePartialMock <ThreadPoolExecutor>(1, 1, Delays.Long,
                                                                      new SynchronousQueue <IRunnable>(), noExceptionFactory);

            ExecutorService = es;

            try
            {
                es.Execute(runnable);
                Thread.Sleep(Delays.Short);
                es.AssertWasCalled(e => e.AfterExecute(runnable, ex));
            }
            finally // workaround a bug in RhinoMocks.
            {
                es.Shutdown();
                Thread.Sleep(Delays.Short);
            }
            JoinPool(es);
            ThreadManager.JoinAndVerify();
        }
Example #12
0
        public void ExecuteDropsOldestTaskOnShutdownWithDiscardOldestPolicy()
        {
            IRejectedExecutionHandler h = new ThreadPoolExecutor.DiscardOldestPolicy();

            ExecutorService = new ThreadPoolExecutor(1, 1, Delays.Long, new ArrayBlockingQueue <IRunnable>(1), h);
            AssertExecutorDropsTaskOnShutdown(ExecutorService);
        }
Example #13
0
        public void ExecuteDropsTaskWhenSaturatedWithDiscardPolicy()
        {
            IRejectedExecutionHandler h = new ThreadPoolExecutor.DiscardPolicy();
            var es = new ThreadPoolExecutor(1, 1, Delays.Long, new ArrayBlockingQueue <IRunnable>(1), h);

            ExecutorService = es;
            IRunnable[] tasks = new IRunnable[_size];
            for (int i = 0; i < _size; ++i)
            {
                tasks[i] = MockRepository.GenerateStub <IRunnable>();
            }

            es.Execute(_mediumInterruptableAction);
            for (int i = 0; i < _size; ++i)
            {
                es.Execute(tasks[i]);
            }

            for (int i = 1; i < _size; ++i)
            {
                tasks[i].AssertWasNotCalled(r => r.Run());
            }
            InterruptAndJoinPool(es);
            ThreadManager.JoinAndVerify();
        }
Example #14
0
        public static IExecutor CreateThreadPoolTaskExecutor(int coreSize, int maxSize, int queueCapacity, string threadPrefix)
        {
            IBlockingQueue <IRunnable> queue = queueCapacity > 0 ? new LinkedBlockingQueue <IRunnable>(queueCapacity) : new LinkedBlockingQueue <IRunnable>();
            var executor = new ThreadPoolExecutor(coreSize, maxSize, TimeSpan.Zero, queue);

            if (StringUtils.HasText(threadPrefix))
            {
                // TODO new CustomizableThreadFactory(threadPrefix);
                //executor.ThreadFactory = new CustomizableThreadFactory(threadPrefix);
            }

            executor.RejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
            // TODO executor.AfterPropertiesSet();
            return(executor);


            /*
             *
             * ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
             * executor.CorePoolSize = coreSize;
             * executor.MaxPoolSize = maxSize;
             * executor.QueueCapacity = queueCapacity;
             * if (StringUtils.HasText(threadPrefix))
             * {
             *  executor.ThreadFactory = new CustomizableThreadFactory(threadPrefix);
             * }
             * executor.RejectedExecutionHandler = new CallerRunsPolicy();
             * executor.AfterPropertiesSet();
             * return executor;
             */
        }
 [SetUp] public void SetUp()
 {
     _queue              = MockRepository.GenerateStub <IBlockingQueue <IRunnable> >();
     _runnable           = MockRepository.GenerateMock <IRunnable>();
     _callerRunsPolicy   = new ThreadPoolExecutor.CallerRunsPolicy();
     _threadPoolExecutor = new ThreadPoolExecutor(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
Example #16
0
 [SetUp] public void SetUp()
 {
     _queue               = MockRepository.GenerateStub <IBlockingQueue <IRunnable> >();
     _runnable            = MockRepository.GenerateMock <IRunnable>();
     _discardOldestPolicy = new ThreadPoolExecutor.DiscardOldestPolicy();
     _threadPoolExecutor  = Mockery.GeneratePartialMock <ThreadPoolExecutor>(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
Example #17
0
        [Test] public void ForEachLimitsParallismToThreadPoolExecutorCoreSize(
            [Values(Parallelism - 2, Parallelism + 2)] int coreSize)
        {
            var tf       = new ManagedThreadFactory(ThreadManager);
            var executor = new ThreadPoolExecutor(coreSize, Parallelism + 2,
                                                  TimeSpan.MaxValue, new LinkedBlockingQueue <IRunnable>(1), tf);

            try
            {
                T[] sources = TestData <T> .MakeTestArray(_sampleSize);

                List <T> results  = new List <T>(_sampleSize);
                var      parallel = new ParallelCompletion <T, int>(executor,
                                                                    _localInit,
                                                                    (t, s, l) =>
                {
                    Thread.Sleep(10); lock (results) results.Add(t);
                    return(0);
                },
                                                                    _localFinally);
                parallel.ForEach(sources, Parallelism);
                Assert.That(results, Is.EquivalentTo(sources));
                Assert.That(parallel.ActualDegreeOfParallelism, Is.EqualTo(Math.Min(Parallelism, coreSize)));
            }
            finally
            {
                executor.ShutdownNow();
            }

            ThreadManager.JoinAndVerify();
        }
Example #18
0
 internal ExecutorDispatcher(int availableThreads, int numberOfDispatchers, float numberOfDispatchersFactor)
 {
     _maxAllowedConcurrentThreads = numberOfDispatchers > 0 ?
                                    numberOfDispatchers : (int)(availableThreads * numberOfDispatchersFactor);
     _closed   = new AtomicBoolean(false);
     _executor = new ThreadPoolExecutor(_maxAllowedConcurrentThreads, HandleRejection);
 }
Example #19
0
 /// <summary>
 /// Create a AsyncDiskServices with a set of volumes (specified by their
 /// root directories).
 /// </summary>
 /// <remarks>
 /// Create a AsyncDiskServices with a set of volumes (specified by their
 /// root directories).
 /// The AsyncDiskServices uses one ThreadPool per volume to do the async
 /// disk operations.
 /// </remarks>
 /// <param name="volumes">The roots of the file system volumes.</param>
 public AsyncDiskService(string[] volumes)
 {
     /*
      * This class is a container of multiple thread pools, each for a volume,
      * so that we can schedule async disk operations easily.
      *
      * Examples of async disk operations are deletion of files.
      * We can move the files to a "TO_BE_DELETED" folder before asychronously
      * deleting it, to make sure the caller can run it faster.
      */
     // ThreadPool core pool size
     // ThreadPool maximum pool size
     // ThreadPool keep-alive time for threads over core pool size
     threadFactory = new _ThreadFactory_73(this);
     // Create one ThreadPool per volume
     for (int v = 0; v < volumes.Length; v++)
     {
         ThreadPoolExecutor executor = new ThreadPoolExecutor(CoreThreadsPerVolume, MaximumThreadsPerVolume
                                                              , ThreadsKeepAliveSeconds, TimeUnit.Seconds, new LinkedBlockingQueue <Runnable>()
                                                              , threadFactory);
         // This can reduce the number of running threads
         executor.AllowCoreThreadTimeOut(true);
         executors[volumes[v]] = executor;
     }
 }
Example #20
0
 private void EnsureExecutorInitialized()
 {
     if (executor == null)
     {
         executor = executorService.GetExecutor(ExecutorOptionsBuilder.Options);
     }
 }
 public void SetUp()
 {
     _queue = MockRepository.GenerateStub<IBlockingQueue<IRunnable>>();
     _runnable = MockRepository.GenerateMock<IRunnable>();
     _discardOldestPolicy = new ThreadPoolExecutor.DiscardOldestPolicy();
     _threadPoolExecutor = Mockery.GeneratePartialMock<ThreadPoolExecutor>(1, 1, TimeSpan.FromSeconds(1), _queue);
 }
Example #22
0
        public void ExecuteRunsTaskInCurrentThreadWhenSaturatedWithCallerRunsPolicy()
        {
            IRejectedExecutionHandler h = new ThreadPoolExecutor.CallerRunsPolicy();
            var es = new ThreadPoolExecutor(1, 1, Delays.Long, new ArrayBlockingQueue <IRunnable>(1), h);

            ExecutorService = es;
            IRunnable[] tasks  = new IRunnable[_size];
            var         caller = Thread.CurrentThread;

            for (int i = 0; i < _size; ++i)
            {
                tasks[i] = MockRepository.GenerateStub <IRunnable>();
                tasks[i].Stub(r => r.Run()).Do(
                    ThreadManager.GetManagedAction(
                        () => Assert.That(Thread.CurrentThread, Is.EqualTo(caller))));
            }

            es.Execute(_mediumInterruptableAction);
            for (int i = 0; i < _size; ++i)
            {
                es.Execute(tasks[i]);
            }

            for (int i = 1; i < _size; ++i)
            {
                tasks[i].AssertWasCalled(r => r.Run());
            }
            InterruptAndJoinPool(es);
            ThreadManager.JoinAndVerify();
        }
Example #23
0
        internal ThreadPoolImpl(int minPoolSize, int maxPoolSize)
        {
            // TODO: check is these defaults make any size

            // minimum 4
            _minPoolSize = minPoolSize > 0 ? minPoolSize : Math.Max(4, GetNumCores() - 1);

            // CLR has max 250 threads per core...

            if (maxPoolSize <= 0)
            {
                // min-max 20;
                var maxThreadsMultiplier = 4;
                maxPoolSize = (_minPoolSize + 1) * maxThreadsMultiplier;
            }

            if (maxPoolSize < minPoolSize)
            {
                maxPoolSize = minPoolSize;
            }

            var queue = new RunnableQueue(this);

            _threadPool = new ThreadPoolExecutor(_minPoolSize, maxPoolSize, 60L, TimeUnit.SECONDS, queue);

            // there could be some logic to automatic reduce the number of threads again if they are
            // not needed. For now, we have the MemoryPressure approach.
            // TODO: MemoryPressure should automatically be called when Android signals memory pressure,
            //       probalby best from Dot42.Internal.Application.
        }
        public static ITaskScheduler CreateTaskScheduler(int poolSize)
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor(
                poolSize, poolSize, new TimeSpan(0, 0, 10), new LinkedBlockingQueue <IRunnable>(), new ThreadPoolExecutor.CallerRunsPolicy()
                );

            return(new SimpleTaskScheduler(executor));
        }
Example #25
0
 private ReadaheadPool()
 {
     pool = new ThreadPoolExecutor(PoolSize, MaxPoolSize, 3L, TimeUnit.Seconds, new ArrayBlockingQueue
                                   <Runnable>(Capacity));
     pool.SetRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
     pool.SetThreadFactory(new ThreadFactoryBuilder().SetDaemon(true).SetNameFormat("Readahead Thread #%d"
                                                                                    ).Build());
 }
Example #26
0
        [Test] public void UnconfigurableExecutorCannotBeCastedToConcreteImplementation()
        {
            var original       = new ThreadPoolExecutor(1, 1, TimeSpan.Zero, new LinkedBlockingQueue <IRunnable>());
            IExecutorService e = Executors.UnconfigurableExecutorService(original);

            Assert.That(e, Is.Not.InstanceOf <ThreadPoolExecutor>());
            JoinPool(e);
        }
        public void ExecuteTest()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor(10, Executors.DefaultThreadFactory());

            executor.Execute(new RunnableAction(delegate {
                Console.WriteLine("Yarrrrr!");
            }));
        }
Example #28
0
        [Test] public void KeepAliveTimeRetunsValueGevinInConstructor([Values(1, 3)] int keepAliveSeconds)
        {
            var keepAlive = TimeSpan.FromSeconds(keepAliveSeconds);

            ExecutorService = new ThreadPoolExecutor(2, 2, keepAlive, new ArrayBlockingQueue <IRunnable>(10));
            Assert.AreEqual(keepAlive, ExecutorService.KeepAliveTime);
            JoinPool(ExecutorService);
        }
Example #29
0
 /// <summary>
 /// Executes task <paramref name="runnable"/> in the caller's thread, unless <paramref name="executor"/>
 /// has been shut down, in which case the task is discarded.
 ///
 /// <param name="executor">the executor attempting to execute this task</param>
 /// <param name="runnable">the runnable task requested to be executed</param>
 /// </summary>
 public void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
     if (executor.IsShutdown)
     {
         return;
     }
     runnable.Run();
 }
 public AsyncServerUserProcessor()
 {
     this.delaySwitch   = false;
     this.isException   = false;
     this.delayMs       = 0;
     this.executor      = new ThreadPoolExecutor(1, 3, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(4), new NamedThreadFactory("Request-process-pool"));
     this.asyncExecutor = new ThreadPoolExecutor(1, 3, 60, TimeUnit.SECONDS, new ArrayBlockingQueue(4), new NamedThreadFactory("Another-aysnc-process-pool"));
 }
Example #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HystrixThreadPoolDefault"/> class.
        /// </summary>
        /// <param name="threadPoolKey">The key of this thread pool.</param>
        /// <param name="setter">The default properties of this thread pool.</param>
        public HystrixThreadPoolDefault(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolPropertiesSetter setter)
        {
            this.properties = HystrixPropertiesFactory.GetThreadPoolProperties(threadPoolKey, setter);
            this.queue      = HystrixPlugins.Instance.ConcurrencyStrategy.GetBlockingQueue(this.properties.MaxQueueSize.Get());
            this.threadPool = HystrixPlugins.Instance.ConcurrencyStrategy.GetThreadPool(threadPoolKey, this.properties.CoreSize, this.properties.CoreSize, this.properties.KeepAliveTime, this.queue);
            this.metrics    = HystrixThreadPoolMetrics.GetInstance(threadPoolKey, this.threadPool, this.properties);

            HystrixMetricsPublisherFactory.CreateOrRetrievePublisherForThreadPool(threadPoolKey, this.metrics, this.properties);
        }
Example #32
0
        /// <summary>
        /// Default ctor
        /// </summary>
        internal ThreadPoolScheduler(bool isIOScheduler)
        {
            lowMaxPoolSize  = Math.Max(1, numCores - 1);
            highMaxPoolSize = isIOScheduler ? lowMaxPoolSize * 2 : lowMaxPoolSize * 3;
            var queue = new RunnableQueue();

            threadPool     = new ThreadPoolExecutor(lowMaxPoolSize, lowMaxPoolSize, 60L, TimeUnit.SECONDS, queue);
            queue.Executor = threadPool;
        }
        public void TestConstructor()
        {
            ThreadPoolExecutor executor = new ThreadPoolExecutor();

            Assert.IsNotNull(executor);
            Assert.IsFalse(executor.IsShutdown);
            executor.Shutdown();
            Assert.IsTrue(executor.IsShutdown);
        }
Example #34
0
		/// <summary> 
		/// Always throws <see cref="Spring.Threading.Execution.RejectedExecutionException"/>.
		/// </summary>
		/// <param name="runnable">the <see cref="Spring.Threading.IRunnable"/> task requested to be executed</param>
		/// <param name="executor">the <see cref="Spring.Threading.Execution.ThreadPoolExecutor"/> attempting to execute this task</param>
		/// <exception cref="Spring.Threading.Execution.RejectedExecutionException">Always thrown upon execution.</exception>
        public virtual void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
		{
			throw new RejectedExecutionException("IRunnable: " + runnable + " rejected from execution by ThreadPoolExecutor: " + executor);
		}
Example #35
0
        public void configure(String[] args)
        {
            // create app properties, using the default values as initial values
            appProperties = new Dictionary<String, String>(defaultProperties);

            // parse command line on top of defaults
            parseCommandLine(args, appProperties);

            // load properties from application.properties file over the defaults
            loadProperties(appProperties, PROPERTIES_PATH);

            // now load database properties file over the application and the defaults
            loadProperties(appProperties, DB_PROPERTIES_PATH);

            // parse the command line into app properties, as command line overrides all others
            parseCommandLine(args, appProperties);

            resolveReferences(appProperties);

            String[] keys = appProperties.Keys.ToArray();
            Array.Sort(keys);

            String helpOption;
            if (appProperties.TryGetValue("help", out helpOption) && "true".Equals(helpOption, StringComparison.InvariantCultureIgnoreCase)) {
                Console.Out.WriteLine("\nCSNuoTest [option=value [, option=value, ...] ]\nwhere <option> can be any of:\n");

                foreach (String key in keys) {
                    Console.Out.WriteLine(String.Format("{0}\t\t\t\t(default={1})", key, defaultProperties[key]));
                }

                Console.Out.WriteLine("\nHelp called - nothing to do; exiting.");
                Environment.Exit(0);
            }

            appLog.info("command-line properties: {0}",  string.Join(";", appProperties));

            StringBuilder builder = new StringBuilder(1024);
            builder.Append("\n***************** Resolved Properties ********************\n");
            foreach (String key in keys) {
                builder.AppendFormat("{0} = {1}\n", key, appProperties[key]);
            }
            appLog.info("{0}**********************************************************\n", builder.ToString());

            runTime = Int32.Parse(appProperties[RUN_TIME]) * Millis;
            averageRate = Single.Parse(appProperties[AVERAGE_RATE]);
            minViewAfterInsert = Int32.Parse(appProperties[MIN_VIEW_DELAY]);
            maxViewAfterInsert = Int32.Parse(appProperties[MAX_VIEW_DELAY]);
            timingSpeedup = Single.Parse(appProperties[TIMING_SPEEDUP]);
            minGroups = Int32.Parse(appProperties[MIN_GROUPS]);
            maxGroups = Int32.Parse(appProperties[MAX_GROUPS]);
            minData = Int32.Parse(appProperties[MIN_DATA]);
            maxData = Int32.Parse(appProperties[MAX_DATA]);
            burstProbability = Single.Parse(appProperties[BURST_PROBABILITY_PERCENT]);
            minBurst = Int32.Parse(appProperties[MIN_BURST]);
            maxBurst = Int32.Parse(appProperties[MAX_BURST]);
            maxQueued = Int32.Parse(appProperties[MAX_QUEUED]);
            initDb = Boolean.Parse(appProperties[DB_INIT]);
            queryOnly = Boolean.Parse(appProperties[QUERY_ONLY]);
            queryBackoff = Int32.Parse(appProperties[QUERY_BACKOFF]);
            maxRetry = Int32.Parse(appProperties[MAX_RETRY]);
            retrySleep = Int32.Parse(appProperties[RETRY_SLEEP]);

            String threadParam;
            int insertThreads = (appProperties.TryGetValue(INSERT_THREADS, out threadParam) ? Int32.Parse(threadParam) : 1);

            int queryThreads = (appProperties.TryGetValue(QUERY_THREADS, out threadParam) ? Int32.Parse(threadParam) : 1);

            if (maxViewAfterInsert > 0 && maxViewAfterInsert < minViewAfterInsert) {
                maxViewAfterInsert = minViewAfterInsert;
            }

            if (maxBurst <= minBurst) {
                appLog.info("maxBurst ({0}) <= minBurst ({1}); burst disabled", maxBurst, minBurst);
                burstProbability = minBurst = maxBurst = 0;
            }

            // filter out database properties, and strip off the prefix
            Dictionary<String, String> dbProperties = new Dictionary<String, String>();
            String dbPropertyPrefix = appProperties[DB_PROPERTY_PREFIX];
            if (! dbPropertyPrefix.EndsWith(".")) dbPropertyPrefix = dbPropertyPrefix + ".";

            foreach (String key in appProperties.Keys) {
                if (key.StartsWith(dbPropertyPrefix)) {
                    dbProperties[key.Substring(dbPropertyPrefix.Length)] = appProperties[key];
                }
            }

            //String insertIsolation = appProperties.getProperty(UPDATE_ISOLATION);
            //DataSource dataSource = new com.nuodb.jdbc.DataSource(dbProperties);
            SqlSession.init(dbProperties, insertThreads + queryThreads);

            SqlSession.CommunicationMode commsMode;
            if (!Enum.TryParse<SqlSession.CommunicationMode>(appProperties[COMMUNICATION_MODE], out commsMode))
                commsMode = SqlSession.CommunicationMode.SQL;
            SqlSession.globalCommsMode = commsMode;
            appLog.info("SqlSession.globalCommsMode set to {0}", commsMode);

            SqlSession.SpNamePrefix = appProperties[SP_NAME_PREFIX];

            ownerRepository = new OwnerRepository();
            ownerRepository.init();

            groupRepository = new GroupRepository();
            groupRepository.init();

            dataRepository = new DataRepository();
            dataRepository.init();

            eventRepository = new EventRepository(ownerRepository, groupRepository, dataRepository);
            eventRepository.init();

            if (!Enum.TryParse<TxModel>(appProperties[TX_MODEL], out txModel))
                txModel = TxModel.DISCRETE;

            if (!Enum.TryParse<SqlSession.Mode>(appProperties[BULK_COMMIT_MODE], out bulkCommitMode))
                bulkCommitMode = SqlSession.Mode.BATCH;

            //insertExecutor = Executors.newFixedThreadPool(insertThreads);
            //queryExecutor= Executors.newScheduledThreadPool(queryThreads);

            insertExecutor = new ThreadPoolExecutor<EventGenerator>("INSERT", insertThreads);
            queryExecutor = new ThreadPoolExecutor<EventViewTask>("QUERY", queryThreads);

            string checkOnly;
            if (appProperties.TryGetValue("check.config", out checkOnly) && checkOnly.Equals("true", StringComparison.InvariantCultureIgnoreCase)) {
                Console.Out.WriteLine("CheckConfig called - nothing to do; exiting.");
                Environment.Exit(0);
            }

            string silent;
            if (appProperties.TryGetValue("silent", out silent) && silent.Equals("true", StringComparison.InvariantCultureIgnoreCase)) {
                Logger.Silent = true;
            }
        }
Example #36
0
		/// <summary> 
		/// Silently discards the <see cref="Spring.Threading.IRunnable"/>
		/// </summary>
		/// <param name="runnable">the <see cref="Spring.Threading.IRunnable"/> task requested to be executed</param>
		/// <param name="executor">the <see cref="Spring.Threading.Execution.ThreadPoolExecutor"/> attempting to execute this task</param>
        public virtual void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
		{
		}
		private void startExecutor() {
			if (executor == null || executor.isShutdown()) {
				executor = new ThreadPoolExecutor(maxThreadPoolSize,
				                              maxThreadPoolSize, 60L, TimeUnit.SECONDS,
				                              new LinkedBlockingQueue<Runnable>(maxQueueSize));
			}
		}
Example #38
0
 /// <summary>
 /// Executes task <paramref name="runnable"/> in the caller's thread, unless <paramref name="executor"/> 
 /// has been shut down, in which case the task is discarded.
 ///
 /// <param name="executor">the executor attempting to execute this task</param>
 /// <param name="runnable">the runnable task requested to be executed</param>
 /// </summary>
 public void RejectedExecution(IRunnable runnable, ThreadPoolExecutor executor)
 {
     if (executor.IsShutdown) return;
     runnable.Run();
 }