简体   繁体   English

C#Performance MS verse Mono Problems

[英]C# Performance MS verse Mono Problems

I'm working on a fairly straight-forward (school) project. 我正在开展一个相当简单的(学校)项目。 It's a job-shop scheduler. 这是一个工作车间调度员。 It's single-threaded, it has very limited File I/O (it reads a small problem description, then it goes to work trying to build a solution). 它是单线程的,它具有非常有限的文件I / O(它读取一个小问题描述,然后它开始尝试构建解决方案)。 The CPU should be the bottleneck. CPU应该是瓶颈。 There is no user input/GUI. 没有用户输入/ GUI。

On my machine, in release mode, without the debugger - in 3 minutes of CPU time, my PC can generate/evaluate 20,000 different schedules for a particular problem. 在我的机器上,在发布模式下,没有调试器 - 在3分钟的CPU时间内,我的PC可以针对特定问题生成/评估20,000个不同的计划。

On a comparable *nix machine, executed with mono, in 3 minutes of CPU time, the server manages to generate/evaluate 2,000 different schedules. 在类似的* nix机器上,使用单声道执行,在3分钟的CPU时间内,服务器设法生成/评估2,000个不同的时间表。 It's 1/10th the speed . 它是速度的十分之一 I've compared Python performance between my machine and this particular server and the throughput was nearly identical. 我比较了我的机器和这个特定服务器之间的Python性能,吞吐量几乎相同。

The only 'system' call that I could see as being different was a call to 唯一可以看到不同的“系统”呼叫是呼叫

Process.GetCurrentProcess().TotalProcessorTime.Minutes

But removing it hasn't had any impact. 但删除它没有任何影响。

I've tried using 我试过用了

--aot -O=all --aot -O =全部

It didn't have any noticeable impact. 它没有任何明显的影响。

I've also tried to run the mono profiler against it but the results haven't been as helpful as I had hoped. 我也尝试对它运行单声道探测器,但结果并没有像我希望的那样有用。

  Hits      % Method name
 57542  37.45 /usr/bin/mono
 11432   7.44 __lll_unlock_wake                    in /lib64/libpthread.so.0
  6898   4.49 System.Linq.Enumerable:Any<jobshop2.JobTask> (System.Collections.Generic.IEnumerable`1<jobshop2.JobTask>,System.Func`2<jobshop2.JobTask, bool>)
  6857   4.46 System.Collections.Generic.List`1/Enumerator<jobshop2.JobTask>:MoveNext ()
  3582   2.33 pthread_cond_wait@@GLIBC_2.3.2       in /lib64/libpthread.so.0
  2719   1.77 __lll_lock_wait                      in /lib64/libpthread.so.0

Of those top six lines - I only recognize two of them as being 'my code' that I could improve upon. 在前六行中 - 我只承认其中两个是我的代码,我可以改进。 In the full output I can see quite a few calls in /lib64/libpthread.so.0 that seem to deal with locking, unlocking, waiting, mutexes, and pthreads. 在完整输出中,我可以在/lib64/libpthread.so.0中看到很多调用,它们似乎处理锁定,解锁,等待,互斥和pthread。 I'm confused by this because it is not a multi-threaded application. 我对此感到困惑,因为它不是一个多线程的应用程序。

I'm going through the Performance page on the mono site but nothing is really jumping out at me as being a problem. 我正在通过单声道网站上的性能页面,但没有什么是真正的跳出来作为一个问题。 I have no doubt that my code is ugly and slow, but I really wasn't expecting such a big performance drop. 我毫不怀疑我的代码是丑陋而缓慢的,但我真的没想到会有如此大的性能下降。 I'm currently trying to get Linux installed on my desktop so that I can run my app in mono on the same hardware to help eliminate that variable - but I thought someone might be able to offer some suggestions/insight. 我目前正在尝试在我的桌面上安装Linux,以便我可以在同一硬件上以单声道运行我的应用程序以帮助消除该变量 - 但我认为有人可能能够提供一些建议/见解。

EDIT: It is version 2.10.8 mono 编辑:它是版本2.10.8单声道

Mono JIT compiler version 2.10.8 (tarball Sat Feb 16 11:51:56 UTC 2013)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          debugger softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

This is a bit of an awkward answer, but I felt like it was the most fair way to handle it...I can't really explain what the cause was, but I don't want to imply that mono is horribly slow (it really isn't). 这是一个尴尬的答案,但我觉得这是最公平的处理方式......我无法解释原因是什么,但我不想暗示单声道非常缓慢(它真的不是)。

My concern was getting the program to run fast on the server. 我担心的是让程序在服务器上快速运行。 As other people have pointed out, the version of mono installed on the server was very old. 正如其他人所指出的那样,服务器上安装的单声道版本非常老旧。 I hope nobody sees my question and thinks that it reflects the current state of mono. 我希望没有人看到我的问题,并认为它反映了当前的单声道状态。 Sadly, I am not able to update the version of mono on the server. 遗憾的是,我无法在服务器上更新mono版本。

So, I re-wrote my code to remove unnecessary computation, avoid using iterators, and to limit memory allocations. 所以,我重新编写了我的代码来删除不必要的计算,避免使用迭代器,并限制内存分配。 My original code was doing a lot of unnecessary creation of objects and the objects were a lot larger than they needed to be. 我的原始代码正在做很多不必要的对象创建,并且对象比他们需要的要大得多。 The clean up doubled the speed on my machine and made the 'server' performance about 70% of my own (a huge improvement!). 清理工作使我的机器速度提高了一倍,并使“服务器”性能达到了我自己的70%(这是一个巨大的改进!)。

Still, it's not fair to compare different hardware - even if previous Python programs 'seemed' to run at about the same speed. 尽管如此,比较不同的硬件是不公平的 - 即使以前的Python程序“似乎”以大致相同的速度运行。 I installed Linux and, with the newest version of mono, installed, my revised program ran at 96% of the Windows version. 我安装了Linux,安装了最新版本的mono,我修改后的程序运行在Windows版本的96%。

I didn't keep digging beyond that. 我没有继续挖掘那个。 Using the current version of mono, on the same hardware, gave me nearly identical performance. 在相同的硬件上使用当前版本的mono,给了我几乎相同的性能。 Thanks for all the suggestions, it was incredibly helpful and saved me a lot of time. 感谢所有的建议,这是非常有帮助的,并节省了我很多时间。

Could be a memory leak. 可能是内存泄漏。 Mono is fighting an uphill battle; Mono正在进行艰苦的战斗; Microsoft made a system and developers had to reverse-engineer most of it. 微软制造了一个系统,开发人员必须对其中的大部分进行逆向工程。 If you really can't figure it out, I would try reporting the bug to the mono developers: 如果你真的无法搞清楚,我会尝试向单声道开发人员报告错误:

Bugs - Mono (http://www.mono-project.com/Bugs) Bugs - Mono(http://www.mono-project.com/Bugs)

Make sure that your mono version is up to date first; 确保您的单声道版本是最新的; 2.10 is ancient. 2.10很古老。 As of now, 3.2.6 is the latest. 截至目前,3.2.6是最新的。 The packaged version from a package maintainer might not be good enough; 来自软件包维护者的打包版本可能不够好; try building it from the source tarball , and using that to run your program, before reporting bugs. 尝试从源代码tarball构建它,并在报告错误之前使用它来运行程序。

If you are using wine-mono or something like that on linux, then make sure that wine and wine-mono are up to date as well. 如果您在linux上使用wine-mono或类似的东西,那么请确保wine和wine-mono也是最新的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM