Cross AppDomain的最低通信性能损失是多少? [英] What is the minimum Cross AppDomain communication performance penalty?

查看:107
本文介绍了Cross AppDomain的最低通信性能损失是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试最小化在同一台计算机上跨AppDomain进行通信的性能损失.在我的玩具示例中,将A类加载到AppDomain 1中.它将创建一个AppDomain 2,并在其中加载一个Class 2实例(Class 2继承自MarshalByRef),以获取代理.然后,类1反复调用代理上不返回任何值的方法.

I am trying to minimize the performance penalty of communicating across AppDomains in the same machine. In my toy example, Class A is loaded in AppDomain 1. It creates an AppDomain 2 and loads there an instance of Class 2 (Class 2 inherits from MarshalByRef) getting back a proxy. Then Class 1 calls repeatedly a method on the proxy that returns no values.

我得到以下结果:

  1. 没有AppDomain,两个类都加载在同一个AppDomain中,第一个重复在第二个上重复调用该方法(该方法没有参数): 2,400万个方法调用/秒
  2. 如上所述两个AppDomain,方法没有参数或出血"字符串参数: 340.000个方法调用/秒
  3. 如上所述的两个AppDomain,一个可序列化的参数(由两个字符串组成的数组):每秒64000次方法调用
  1. No AppDomains, both classes are loaded in the same AppDomain and the first calls repetedly the method on the second (the method has no parameters): 24 million method calls/sec
  2. Two AppDomain as described above, method has no parameters or "bleeding" string parameters: 340.000 methods calls/sec
  3. Two AppDomains as described above, one serializable parameter (array of two strings): 64.000 method calls/sec

尽管我了解2到3之间的性能损失(序列化),但我真的不理解为什么我从案例1到案例2的速度要慢100倍.据我了解,一旦创建代理,所有后续方法调用都必须非常快,因为没有数据从一个AppDomain编组到另一个AppDomain.现在有人为什么跨AppDomains进行交流如此缓慢吗?我在做错什么吗?

Although I understand the performance penalty between 2 and 3 (serialization), I really don't understand why I am 100 times slower from case 1 to case 2. To my understanding, once the proxy is created all subsequent method invocations must be really fast since no data are being marshalled from one AppDomain to the other. Does anybody now why communicating across AppDomains is so slow? Am I doing something wrong?

PS1.我对此唯一的提示是此处: 而且跨越AppDomain边界的成本令人尴尬."我猜他是指序列化...

PS1. The only tip that I have on this is here: "And the cost of crossing an AppDomain boundary is embarrassing.". I was guessing he refers to serialization...

PS2.我不计算AppDomain或Proxy创建时间(我的基准测试从第一个方法调用开始)

PS2. I don't count the AppDomain or Proxy creation time (my benchmarks start in the first method invocation)

PS3.我在WinXP SP3计算机中使用.NET 3.5.我还尝试了.NET 4.0 Beta 1,没有明显的差异.

PS3. I am using .NET 3.5 in a WinXP SP3 machine. I also tried .NET 4.0 Beta 1 with no significant differences.

推荐答案

如果计算每个方案中涉及的IL行,您将看到CLR在进行远程处理时的工作量是100倍以上.直接调用只是一些操作码,但是在远程处理中涉及多个类,真实/透明代理,安全检查,序列化,yadda yadda yadda.您将需要通过设计解决这一问题-没有通过实施来提高性能的万能药.

If you count lines of IL involved in each scenario, you will see that the CLR is doing much more than 100 times the work when remoting. A direct invocation is just a few opcodes, but with remoting there are multiple classes involved, real/transparent proxies, security checks, serialization, yadda yadda yadda. You will need to address this through design - there is no magic bullet for improving perf through implementation.

这篇关于Cross AppDomain的最低通信性能损失是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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