private static DedicatedThreadPoolSettings ConfigureSettings(Config config) { var dtp = config.GetConfig("dedicated-thread-pool"); var fje = config.GetConfig("fork-join-executor"); if ((dtp == null || dtp.IsEmpty) && (fje == null || fje.IsEmpty)) { throw new ConfigurationException( $"must define section 'dedicated-thread-pool' OR 'fork-join-executor' for fork-join-executor {config.GetString("id", "unknown")}"); } if (dtp != null && !dtp.IsEmpty) { var settings = new DedicatedThreadPoolSettings(dtp.GetInt("thread-count"), DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype", ThreadType.Background.ToString())), config.GetString("id"), DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp)); return(settings); } else { var settings = new DedicatedThreadPoolSettings(ThreadPoolConfig.ScaledPoolSize(fje.GetInt("parallelism-min"), 1.0, fje.GetInt("parallelism-max")), name: config.GetString("id")); return(settings); } }
static void Main(string[] args) { var workItems = 100000; var tpSettings = new DedicatedThreadPoolSettings(Environment.ProcessorCount); Console.WriteLine("Comparing Helios.Concurrency.DedicatedThreadPool vs System.Threading.ThreadPool for {0} items", workItems); Console.WriteLine("DedicatedThreadPool.NumThreads: {0}", tpSettings.NumThreads); //Console.WriteLine("System.Threading.ThreadPool"); //Console.WriteLine( // TimeSpan.FromMilliseconds( // Enumerable.Range(0, 6).Select(_ => // { // var sw = Stopwatch.StartNew(); // CreateAndWaitForWorkItems(workItems); // return sw.ElapsedMilliseconds; // }).Skip(1).Average() // ) //); Console.WriteLine("Helios.Concurrency.DedicatedThreadPool"); Console.WriteLine( TimeSpan.FromMilliseconds( Enumerable.Range(0, 6).Select(_ => { var sw = Stopwatch.StartNew(); CreateAndWaitForWorkItems(workItems, tpSettings); return(sw.ElapsedMilliseconds); }).Skip(1).Average() ) ); }
public override IAccessableResource Construct() { var settings = new DedicatedThreadPoolSettings(numberOfThreads, $"{nameof(WhatNow)}.{nameof(ThreadPoolResourceDefinition)}.{Name}"); var pool = new DedicatedThreadPool(settings); return(new ThreadPool(pool, taskCreationOptions)); }
/// <summary> /// Creates a new thread pool. /// </summary> /// <param name="name">A name of this thread pool.</param> /// <param name="threadsNumber">A number of thread in this thread pool. Default value is a count of processors.</param> /// <param name="threadsPriority">A priority of threads in this thread pool. Default value is </param> public FixedThreadPool( string name = null, int?threadsNumber = null, ThreadPriority?threadsPriority = null) { var settings = new DedicatedThreadPoolSettings( threadsNumber ?? Environment.ProcessorCount, threadsPriority, string.IsNullOrWhiteSpace(name) ? "HeliosThreadPool-" + Guid.NewGuid() : name); _threadPool = new DedicatedThreadPool(settings); }
public ForkJoinDispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites) { var dtp = config.GetConfig("dedicated-thread-pool"); if (dtp == null || dtp.IsEmpty) { throw new ConfigurationException(string.Format("must define section dedicated-thread-pool for ForkJoinDispatcher {0}", config.GetString("id", "unknown"))); } var settings = new DedicatedThreadPoolSettings(dtp.GetInt("thread-count"), DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype", ThreadType.Background.ToString())), DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp)); _instance = new ForkJoinDispatcher(this, settings); }
public PinnedDispatcherConfigurator(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites) { var dtp = config.GetConfig("dedicated-thread-pool"); if (dtp == null || dtp.IsEmpty) { _settings = DedicatedThreadPoolConfigHelpers.DefaultSingleThreadPoolSettings; } else { _settings = new DedicatedThreadPoolSettings(1, DedicatedThreadPoolConfigHelpers.ConfigureThreadType(dtp.GetString("threadtype", ThreadType.Background.ToString())), DedicatedThreadPoolConfigHelpers.GetSafeDeadlockTimeout(dtp)); } }
void CreateAndWaitForWorkItems(int numWorkItems, DedicatedThreadPoolSettings settings) { using (ManualResetEvent mre = new ManualResetEvent(false)) { int itemsRemaining = numWorkItems; for (int i = 0; i < numWorkItems; i++) { _threadPool.QueueUserWorkItem(delegate { _counter.Increment(); if (Interlocked.Decrement( ref itemsRemaining) == 0) { mre.Set(); } }); } mre.WaitOne(); } }
static void CreateAndWaitForWorkItems(int numWorkItems, DedicatedThreadPoolSettings settings) { using (ManualResetEvent mre = new ManualResetEvent(false)) using (var tp = new Concurrency.DedicatedThreadPool(settings)) { int itemsRemaining = numWorkItems; for (int i = 0; i < numWorkItems; i++) { tp.EnqueueWorkItem(delegate { if (Interlocked.Decrement( ref itemsRemaining) == 0) { mre.Set(); } }); } mre.WaitOne(); } }
/// <summary> /// Initializes a new instance of the <see cref="ForkJoinExecutorServiceFactory"/> class. /// </summary> /// <param name="config">TBD</param> /// <param name="prerequisites">TBD</param> /// <exception cref="ConfigurationException"> /// This exception is thrown if either 'dedicated-thread-pool' OR 'fork-join-executor' is not defined in <paramref name="config"/>. /// </exception> public ForkJoinExecutorServiceFactory(Config config, IDispatcherPrerequisites prerequisites) : base(config, prerequisites) { _threadPoolConfiguration = ConfigureSettings(config); }
public ForkJoinExecutor(string id, DedicatedThreadPoolSettings poolSettings) : base(id) { _dedicatedThreadPool = new DedicatedThreadPool(poolSettings); }
public void Cleanup() { _threadPool.Dispose(); _settings = null; }
public void Setup(BenchmarkContext context) { _counter = context.GetCounter(BenchmarkCounterName); _settings = new DedicatedThreadPoolSettings(Environment.ProcessorCount); _threadPool = new DedicatedThreadPool(_settings); }
internal SingleThreadDispatcher(MessageDispatcherConfigurator configurator, DedicatedThreadPoolSettings settings) : base(configurator) { _dedicatedThreadPool = new DedicatedThreadPool(settings); }