线程池的程序运行速度更快的服务器上慢得多 [英] Threadpool program runs much slower on much faster server

查看:186
本文介绍了线程池的程序运行速度更快的服务器上慢得多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPD 我认为现在我的问题是根本没有线程,因为我在节目中的任何一点放缓观察。我想以某种方式使用2处理器我的程序执行速度较慢,可能是因为两个处理器需要彼此之间进行交流的时候。我需要做一些测试。我会尝试禁用处理器之一,看看会发生什么。

upd I now think that root of my problem not "threading", because I observe slowdown at any point of my program. I think somehow when using 2 processors my program executes slower probably because two processors need to "communicate" between each other. I need to do some tests. I will try to disable one of the processors and see what happens.

===================== ===============

====================================

我不知道这是C#的问题,可能更有关硬件,但我认为C#将是最合适的。

I'm not sure if this is C# question, probably it more about hardware, but I think C# will be most suitable.

我是用廉价的DL120服务器,我决定升级到更昂贵的双处理器服务器DL360p。没想到我的C#程序运行新的服务器,应该是快好几倍的要慢〜2次。

I was using cheap DL120 server and I decided to upgrade to much more expensive 2 processors DL360p server. Unexpectedly my C# program works about ~2 times slower on new server which supposed to be several times faster.

我处理的 FAST 约60仪器的数据。我创建了单独的任务一样,每个乐器:

I processed FAST data for about 60 Instruments. I have created separate Task for each Instrument like that:

        BlockingCollection<OrderUpdate> updatesQuery;
        if (instrument2OrderUpdates.ContainsKey(instrument))
        {
            updatesQuery = instrument2OrderUpdates[instrument];
        } else
        {
            updatesQuery = new BlockingCollection<OrderUpdate>();
            instrument2OrderUpdates[instrument] = updatesQuery;
            ScheduleFastOrdersProcessing(updatesQuery);
        }
        orderUpdate.Checkpoint("updatesQuery.Add");
        updatesQuery.Add(orderUpdate);
    }

    private void ScheduleFastOrdersProcessing(BlockingCollection<OrderUpdate> updatesQuery)
    {
        Task.Factory.StartNew(() =>
        {
            Instrument instrument = null;
            OrderBook orderBook = null;
            int lastRptSeqNum = -1;
            while (!updatesQuery.IsCompleted)
            {
                OrderUpdate orderUpdate;
                try
                {
                    orderUpdate = updatesQuery.Take();
                } catch(InvalidOperationException e)
                {
                    Log.Push(LogItemType.Error, e.Message);
                    continue;
                }
                orderUpdate.Checkpoint("received from updatesQuery.Take()");
                ......................
                ...................... // long not interesting processing code
        }, TaskCreationOptions.LongRunning);

由于我有大约60任务可以并行我希望执行的是2 * E5-2640( 24个虚拟线程,12线程实)应执行更快于1 * E3-1220(4真线程)。看来,用DL360p我发现95线程任务管理器。使用DL120我只有55个线程。

Because I have about 60 task which can be executed in parallel I expect that 2 * E5-2640 (24 virtual threads, 12 real threads) should perform much more faster than 1 * E3-1220 (4 real threads). It seems that using DL360p I found 95 threads in task manager. Using DL120 I have only 55 threads.

但在DL120G7执行时间为2(!!)倍的速度!
E3-1220有一个更好一点的时钟速度比E5-2640(3.1 GHz的VS 2.5Ghz的),但是我仍然希望我的代码应工作在快2 * E5-2640,因为它可以并联好多了,我绝对不要指望它的工作的2倍慢!

But execution time on DL120G7 is 2 (!!) times faster! E3-1220 has a little bit better clock rate than E5-2640 (3.1 GHz vs 2.5Ghz) however I still expect that my code should work faster on 2 * E5-2640 because it can be paralleled much better and I absolutely do not expect that it work 2 times slower!

HP DL120G7 E3-1220

〜50个线程任务管理器中最好= 24〜平均80微秒

~50 threads in Task Manager best = 24 average ~ 80 microseconds

 calling market.UpdateFastOrder = 23 updatesQuery.Add = 25 received from updatesQuery.Take() = 67 in orderbook = 80
 calling market.UpdateFastOrder = 30 updatesQuery.Add = 32 received from updatesQuery.Take() = 64 in orderbook = 73
 calling market.UpdateFastOrder = 31 updatesQuery.Add = 32 received from updatesQuery.Take() = 195 in orderbook = 204
 calling market.UpdateFastOrder = 31 updatesQuery.Add = 32 received from updatesQuery.Take() = 74 in orderbook = 86
 calling market.UpdateFastOrder = 18 updatesQuery.Add = 21 received from updatesQuery.Take() = 65 in orderbook = 78
 calling market.UpdateFastOrder = 29 updatesQuery.Add = 32 received from updatesQuery.Take() = 76 in orderbook = 88
 calling market.UpdateFastOrder = 30 updatesQuery.Add = 32 received from updatesQuery.Take() = 80 in orderbook = 92
 calling market.UpdateFastOrder = 20 updatesQuery.Add = 21 received from updatesQuery.Take() = 65 in orderbook = 78
 calling market.UpdateFastOrder = 21 updatesQuery.Add = 24 received from updatesQuery.Take() = 68 in orderbook = 81
 calling market.UpdateFastOrder = 12 updatesQuery.Add = 13 received from updatesQuery.Take() = 58 in orderbook = 72
 calling market.UpdateFastOrder = 22 updatesQuery.Add = 23 received from updatesQuery.Take() = 51 in orderbook = 59
 calling market.UpdateFastOrder = 16 updatesQuery.Add = 16 received from updatesQuery.Take() = 20 in orderbook = 24
 calling market.UpdateFastOrder = 28 updatesQuery.Add = 31 received from updatesQuery.Take() = 82 in orderbook = 94
 calling market.UpdateFastOrder = 18 updatesQuery.Add = 21 received from updatesQuery.Take() = 65 in orderbook = 77
 calling market.UpdateFastOrder = 29 updatesQuery.Add = 29 received from updatesQuery.Take() = 259 in orderbook = 264
 calling market.UpdateFastOrder = 49 updatesQuery.Add = 52 received from updatesQuery.Take() = 99 in orderbook = 113
 calling market.UpdateFastOrder = 22 updatesQuery.Add = 23 received from updatesQuery.Take() = 50 in orderbook = 60
 calling market.UpdateFastOrder = 29 updatesQuery.Add = 32 received from updatesQuery.Take() = 76 in orderbook = 88
 calling market.UpdateFastOrder = 16 updatesQuery.Add = 19 received from updatesQuery.Take() = 63 in orderbook = 75
 calling market.UpdateFastOrder = 27 updatesQuery.Add = 27 received from updatesQuery.Take() = 226 in orderbook = 231
 calling market.UpdateFastOrder = 15 updatesQuery.Add = 16 received from updatesQuery.Take() = 35 in orderbook = 42
 calling market.UpdateFastOrder = 18 updatesQuery.Add = 21 received from updatesQuery.Take() = 66 in orderbook = 78

HP DL360p G8 2 * E5-2640

〜95线程任务管理器;最好= 40〜平均150微秒

~95 threads in Task Manager; best = 40 average ~ 150 microseconds

 calling market.UpdateFastOrder = 62 updatesQuery.Add = 64 received from updatesQuery.Take() = 144 in orderbook = 205
 calling market.UpdateFastOrder = 27 updatesQuery.Add = 32 received from updatesQuery.Take() = 101 in orderbook = 154
 calling market.UpdateFastOrder = 45 updatesQuery.Add = 50 received from updatesQuery.Take() = 124 in orderbook = 187
 calling market.UpdateFastOrder = 46 updatesQuery.Add = 51 received from updatesQuery.Take() = 127 in orderbook = 162
 calling market.UpdateFastOrder = 63 updatesQuery.Add = 68 received from updatesQuery.Take() = 137 in orderbook = 174
 calling market.UpdateFastOrder = 53 updatesQuery.Add = 55 received from updatesQuery.Take() = 133 in orderbook = 171
 calling market.UpdateFastOrder = 44 updatesQuery.Add = 46 received from updatesQuery.Take() = 131 in orderbook = 158
 calling market.UpdateFastOrder = 37 updatesQuery.Add = 39 received from updatesQuery.Take() = 102 in orderbook = 140
 calling market.UpdateFastOrder = 45 updatesQuery.Add = 50 received from updatesQuery.Take() = 115 in orderbook = 154
 calling market.UpdateFastOrder = 50 updatesQuery.Add = 55 received from updatesQuery.Take() = 133 in orderbook = 160
 calling market.UpdateFastOrder = 26 updatesQuery.Add = 50 received from updatesQuery.Take() = 99 in orderbook = 111
 calling market.UpdateFastOrder = 14 updatesQuery.Add = 30 received from updatesQuery.Take() = 36 in orderbook = 40   <-- best one I can find among thousands



找到

您能看到为什么我的程序运行速度较慢的几次快2倍的服务器?也许我不应该创建〜60任务?也许我应该告诉.NET不使用95线程,但将其限制在50甚至24?也许这是2处理器VS 1的处理器配置问题?可能只是禁止我DL360P Gen8处理器之一,将加快行动方案显著?

Are you able to see why my program runs 2 times slower on several times faster server? Probably I should not create ~60 Task? Probably I should tell .NET not to use 95 threads but to limit it to 50 or even 24? Probably this is 2 processors vs 1 processor configuration issue? Probably just disabling one of the processors on my DL360P Gen8 will speed-up program significantly?

添加


  • 调用market.UpdateFastOrder - 创建orderUpdate对象

  • updatesQuery.Add - orderUpdate投入BlockingCollection

  • 从updatesQuery.Take()接受 - 从orderUpdate BlockingCollection

  • 在弹出手持订单 - orderUpdated被解析并应用到手持订单

  • calling market.UpdateFastOrder - orderUpdate object is created
  • updatesQuery.Add - orderUpdate is put into BlockingCollection
  • received from updatesQuery.Take() - orderUpdate ejected from BlockingCollection
  • in orderbook - orderUpdated is parsed and applied to orderBook

推荐答案

只是因为你有一个系统,它可以处理更多的线程,这并不意味着所有的人都可以完全并行处理。

just because you have a System which can handle much more threads, this does not mean that all of them can be fully processed parallel.

当我从一个四核CPU升级到i7处理器(虚拟8个内核),我注意到,使用多个线程进行比核导致线程阻塞对方一段时间,从而导致到系统的总体减速

When I upgrade from a Quadcore CPU to a i7(virtual 8 cores), I noticed that a setup using more threads than cores resulted in the threads blocking each other for some time, which lead to an overall slowdown of the System.

的问题是只我algorythims已经有能力使用他们的线程上运行时等待线程核心的完整的处理时间的仅制作约5至10%,这导致主线程完成,但一些烧毛线程仍具有做所有工作(再次考虑相同的时间大写金额)。

The problem was just that my algorythims already were capable of using the full processing time of the core their thread was running on while waiting threads only worked on about 5 to 10%, which lead to the main threads to finish but some singe threads still having to do all their work(taking the same amout of time again).

线程池只会继续,如果所有工人已经完成了,所以时间,直到完成总金额将unuset处理器时间的其他线程。

The threadpool will only continue if all workers have finished, so the total amount of time until finishing will be unuset processor time for the other threads.

您也许只是需要找到线程的最佳数目

maybe you just need to find an optimal number of threads.

这篇关于线程池的程序运行速度更快的服务器上慢得多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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