单线程池并发性问题 [英] Mono ThreadPool concurency issues

查看:262
本文介绍了单线程池并发性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个使用线程池多线程一款软件

I wrote one software that uses ThreadPool for multithreading.

ThreadPool.SetMinThreads(128, 128);
ThreadPool.SetMaxThreads(512, 512);

for (int i = 0; i < 40; i++)
{
    ThreadPool.QueueUserWorkItem(_ =>
    {
        Console.Write("!");
        Thread.Sleep(1000);
        Console.Write(".");
    }, null);
}

每个线程内执行我阻止网络操作(以http作品)。
软件设计围绕阻塞网络模型,我不能移动到非粘着1线程I / O。

Inside each thread I perform blocking network operations(work with http). Software designed around blocking network model and I cannot move to non blocking 1 threaded I/O.

它可以完美运行在Windows平台上,我可以使用128-每一个核心512个线程没有任何问题,所有的工作,因为它应该工作。
,而当我移动到单声道,我看到了一些非常奇怪的行为。我不能让每一个CPU内核运行单的线程,最多我可以得到 - 每核心1个线程,doeesnt'matter什么,我在SetMinThreads / SetMaxThreads指定

It works perfect on windows platform, I can use 128-512 threads per one core without any issues, all work as it should work. But when I moved to mono, I saw some really strange behaviour. I cannot make mono run many threads per one CPU core, max I can get - 1 thread per core, doeesnt'matter what I do specify in SetMinThreads/SetMaxThreads.

试图在Linux下使用.NET 4 / 4.5,单声道版本3.2.1和我以前的系统上的某些旧版本。
顺便说一句,普通的线程代码工作得很好,例如这使期望的结果:

tried under Linux with .NET 4/4.5, MONO version 3.2.1 and some older version on my previous system. Btw, plain threading code works well, for example this gives desired result:

for (int i = 0; i < 20; i++)
{
   var t = new Thread(_ => {
      Console.Write("!");
      Thread.Sleep(1000);
      Console.Write(".");
   });
   t.Start();
}



任何想法?

Any ideas?

推荐答案

我们也已经有很多尝试单,看起来,继帮助:

We've also experimented alot with mono and looks that following helps:


  1. 设置环境变量MONO_THREADS_PER_CPU较高数值。例如
    出口MONO_THREADS_PER_CPU = 300(Linux版)。我'不知道,但看起来你无法通过调整setmin /最大线程数的线程池,而不集每个CPU更多的线程。

  2. 运行单与--server交换机,但它的工作原理从3.2.3开始。这里解释 http://www.mono-project.com/Release_Notes_Mono_3.2
    ,但可能是这个标志可以帮助在启动时,只有不足够的线程被解雇。

我们正在使用这两个选项和Mono在Linux上演戏相当快(媲美.NET在Windows上)

We're using both options and mono on linux acting quite fast( comparable to .net on windows )

这篇关于单线程池并发性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆