Remoting (.NET 1.1) Performance Guidelines - MarshalByRef vs. MarshalByValue

From Guidance Share

Jump to: navigation, search

- J.D. Meier, Srinath Vasireddy, Ashish Babbar, and Alex Mackman


Contents

Use MBR when the object state should stay in the host application domain.

If the state of the object is relevant only in the host's application domain, use MBR. For example, if the object is referencing a handle to a file or other source such as a database network connection, use MBR. You may also want to use MBR when you do not want to serialize and send sensitive data over the network.

Marshal-by-reference (MBR) objects are accessed by using a proxy object in the source application domain. The .NET remoting infrastructure marshals the calls, sends them to the remote application domain, and invokes the call on the actual object.

MBR can result in chatty calls over the network if the object's interface has not been designed efficiently for remote access. Also, the client proxy may throw exceptions if the network connection breaks.


Use MBR when you need to update data frequently on the server.

If the data needs to be frequently updated on the server, using a MBV may serve as a costly option. Use MBR to reduce the cost of serializing the whole of the object. The proxy marshals the data to the server's application domain.


Use MBR when the size of the object is prohibitively large.

If the size of the object is prohibitively large, it makes sense to use MBR. In this way, the client can access the object's resource directly from the server with only the most relevant data getting passed over the network.


Use MBV when you need to pass object state to the target application domain.

When the state of the object is very lightweight and can easily be passed across application boundaries, use MBV objects. This reduces the lengthy, resource consuming round trips across processes, and application domain boundaries.

Marshal-by-value (MBV) objects declare their marshaling rules, either by implementing their own serialization by implementing the ISerializable interface, or by being marked with the Serializable attribute.


Use MBV when you do not need to update data on the server.

MBV objects are appropriate when the data does not need to be updated on the server and needs only to be passed to the client. This can save server resources, network latency, and network bandwidth.


Use small MBV objects when you need to update data frequently on the server.

If you frequently need to update data on the server, use small MBV objects where the complete state of the object is passed to the server. Using MBV reduces the marshaling and unmarshaling overhead associated with MBR, especially where non-blittable types are passed.

Personal tools