为什么我的代码没有使用可用的处理器周期?

发布于 2024-09-15 22:48:32 字数 810 浏览 7 评论 0 原文

我为 ESRI ArcEditor 编写了一个插件,可以在道路网络上运行一些验证检查。为了检查规则是否全部满足,它基本上会在选定的特征上进行一系列不同的相交,并进行一些缓冲和包络等。

它是用 C# 编写的。

现在我注意到的是,在选定的功能上运行给定的算法确实需要很长时间。我加载了 ANTS 分析器并优化了瓶颈,直到我无能为力。

我注意到的一件奇怪的事情是,ANTS 在时间线中几乎没有报告 CPU 使用情况 - 一条平坦的线。然后,我在验证操作运行时使用任务管理器验证处理器是否保持在大约 10% 到 15% 以下。这对我来说毫无意义。为什么它不使用可用的处理器周期?

当它从 ArcSDE 加载所有内容时,没有发生任何 I/O。我还验证了验证过程中没有明显的网络流量,认为它可能正在等待 ArcEditor 和服务器之间的通信。 然后,我检查了服务器上的处理器,以确保没有将任何处理委托给它,但在验证过程中,它的 CPU 使用率保持稳定在 1%。

然后我认为 ArcEditor 可能会抑制其插件可以运行的优先级,或者类似的疯狂行为。所以我插入了一个数学运算,它可以使 CPU 最大化大约 10 秒,而不是验证例程,它就做到了这一点。 CPU 使用率稳定在 50% 以上,这是有道理的,因为数学运算会最大化我的 Core 2 Duo 的一个核心。所以没有运气。并且有超过 1GB 的可用 RAM。

最后,我一直试图找到 perfmon 的问题,但没有运气。没有太多的经验,但也没有发现什么问题。

是因为ArcObjects COM接口吗?尽管我也使用 perfmon 检查了 .NET Interop 计数器。

我不知所措。

因此,任何帮助或提示将不胜感激。

I have written a plugin for ESRI ArcEditor that runs some validation checks on a road network. To check if the rules are all satisfied, it basically does a whole bunch of different intersects, with some buffering and envelopes etc. on the selected features.

It has been written in C#.

Now what I am noticing is that it really takes a long time to run the given algorithms on the selected features. I loaded up ANTS profiler and optimized the bottlenecks until there is very little else I can do.

A strange thing I noticed is that ANTS reported virtually no CPU usage in the timeline - a flatline. I then verified that the processor stays below about 10% to 15% using Task Manager while the validation operation is running. This makes no sense to me. Why is it not using available processor cycles?

There is no I/O that is happening as it loads everything from ArcSDE. I also verified that there is no appreciable network traffic during the validation process, thinking it was perhaps waiting for coms between ArcEditor and the server.
I then checked the processors on the server just to make sure that no processing was being delegated to it, but it's CPU usage remained steady on 1% during the validation process.

I then thought that ArcEditor is perhaps suppressing the priority that it's plugins can run in, or something crazy like that. So I plugged in a maths op that would max out the CPU for about 10 secs, instead of the validation routine, and it did just that. CPU usage was steady at just over 50%, which makes sense as the maths op would max out one of the cores of my Core 2 Duo. So no luck there. And there is more than 1GB RAM available.

Lastly, I have been trying to find the problem with perfmon, but have had no luck there. Haven't had much experience with it, but can't find anything wrong.

Is it because of ArcObjects COM interface? Although I did also check .NET Interop counters with perfmon.

I am at a loss.

So any help or tips would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不在是我 2024-09-22 22:48:32

可能是线程问题。 COM 会自动将 COM 接口上的方法调用编组到正确的线程。通常是程序的UI线程。这非常慢,因为它需要线程上下文切换,并且 UI 线程必须处于分派调用的状态。很少有 CPU 周期被消耗,一切都在阻塞,直到调用完成。

在创建 COM 对象的同一线程上使用该对象。如果对象有 STA 要求,则应该是 UI 线程。他们通常会这样做。

Could be a threading problem. COM will automatically marshal method calls on a COM interface to the proper thread. Which is usually the UI thread of the program. This is very slow since it requires a thread context switch and the UI thread must be in a state to dispatch the call. Few CPU cycles are burned, everything is blocking until the call can complete.

Use the COM object on the same thread as it was created. Which ought to be the UI thread if this the object has STA requirements. They usually do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文