如何昂贵的使用MarshalByRefObject的相比,序列化? [英] How expensive is using MarshalByRefObject compared to serialization?

查看:264
本文介绍了如何昂贵的使用MarshalByRefObject的相比,序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Azure Web角色code我从 System.Security.Principal.IIdentity CustomIdentity 类C>。在某些时候,.NET运行库试图序列化类和的序列化是行不通的。试图解决我搜索了很多,发现<一href="http://stackoverflow.com/questions/1884030/implementing-a-custom-identity-and-iprincipal-in-mvc/3214178#3214178">this回答并试图从 MarshalByRefObject的 继承我的班

In my Azure web role code I have a CustomIdentity class derived from System.Security.Principal.IIdentity. At some point .NET runtime tries to serialize that class and serialization wouldn't work. Trying to resolve that I searched a lot and found this answer and tried to inherit my class from MarshalByRefObject.

现在一旦我的 CustomIdentity 类从 MarshalByRefObject的继承存在了是没有序列化的企图和我的code作品。不过,我想知道使用的性能影响 MarshalByRefObject的类。

Now once my CustomIdentity class inherits from MarshalByRefObject there're no serialization attempts anymore and my code works. However I'd like to know the performance implications of using MarshalByRefObject class.

我的code运行这样。首先请求到达IIS,并传递给认证code,创建 CustomIdentity 的实例,并附加该实例HTTP上下文。然后,一段时间后,同样的HTTP上下文传递给访问最多一次是 CustomIdentity 实例的ASP.NET处理程序。该 CustomIdentity 对象为居住请求的时间,然后销毁。

My code runs like this. First the request comes to IIS and is passed to the authentication code that creates an instance of CustomIdentity and attaches that instance to HTTP context. Then some time later the same HTTP context is passed to the ASP.NET handler that accesses that CustomIdentity instance at most once. The CustomIdentity object lives for the duration of request and is then destroyed.

现在系列化我的 CustomIdentity 将被序列化到一个流,然后从该流反序列化到一个新的对象。随着 MarshalByRefObject的有没有序列化,但创建一个代理和接入将通过RPC编组到实际的对象所在。

Now with serialization my CustomIdentity would be serialized into a stream, then deserialized from that stream into a new object. With MarshalByRefObject there's no serialization but a proxy is created and the access will be marshaled via RPC to where the actual object resides.

如何昂贵将使用 MarshalByRefObject的在这种情况下?其中 - MarshalByRefObject的或序列号 - 将会更加昂贵

How expensive will using MarshalByRefObject be in this scenario? Which - MarshalByRefObject or serialization - will be more costly?

推荐答案

MarshalByRefObject的意味着所有的电话的(方法,属性等)是代理通过线路。这可能意味着,而不是传输数据的一次的,然后运行多种方法等本地上传输的数据,你是一个网络调用的每次访问的。有多少(每个请求)时代是一个角色进行测试,例如?或名称查询?我真的不知道,但我猜它比1(全部总计)。加上原来的安装成本...

MarshalByRefObject means that all calls (methods, properties, etc) are proxied over the wire. This potentially means that instead of transferring the data once and then running multiple methods etc locally on the transferred data, you are making a network call every access. How many times (per request) is a role tested, for example? or the name queried? I honestly don't know, but I'm guessing it is more than 1 (all totalled). Plus the original setup costs...

带宽可能不会显著,但延迟的非常显著,特别是如果你已经分发节点(因为你提到云计算方案)。

The bandwidth probably won't be significant, but latency is very significant, especially if you have distributed nodes (since you mention a cloud scenario).

就个人而言,我会避免 MarshalByRefObject的瘟疫一样,但到你...

Personally, I would avoid MarshalByRefObject like the plague, but up to you...

这篇关于如何昂贵的使用MarshalByRefObject的相比,序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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