Remoting (.NET 1.1) Performance Guidelines - Lifetime Considerations

From Guidance Share

Jump to: navigation, search

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


Contents

Tune Default Timeouts Based on Need

To determine appropriate lifetime timeouts for your application, you need to strike a balance between resource utilization on the server and the performance implications of frequently destroying and recreating objects. Increasing an object's lifetime increases your server's memory and resource utilization, while decreasing the lifetime can lead to objects being destroyed too frequently and prematurely.

Note If a client makes a method call to a remote object whose lifetime lease has expired, an exception is thrown.

Tuning the Lease Time

You can fine-tune both the lease timeout and the "renew on call" time, either programmatically or declaratively. To alter application-wide initial lease times, use the following code.

public override Object InitializeLifetimeService() {

   ILease lease = (ILease)base.InitializeLifetimeService();
   if (lease.CurrentState == LeaseState.Initial)
   {
        lease.InitialLeaseTime = TimeSpan.FromMinutes(1);
        lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
         lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
   }
   return lease;

} A better approach is to use the following configuration file settings.


<configuration>

 <system.runtime.remoting>
   <application>
     <lifetime leaseTime="1M" 
               renewOnCallTime="30S"
               leaseManagerPollTime="2M" />
   </application>
 </system.runtime.remoting>

</configuration> Note that the preceding approach changes all remote objects published by the server


Consider using a longer lease time for objects that are expensive to create.

If you use objects that are expensive to create, consider modifying the lease timeouts to allow the object to remain longer than the default 5-minute timeout. For example, if you use a singleton object that incurs an expensive startup process, consider changing the timeout to a longer, more appropriate, period of time, or change the timeout to infinite. The code in the next section shows the changing of the lifetime lease to infinite.


Consider shorter lease times for objects that consume lots of shared or important resources.

If you create objects that consume shared or important resources, consider using a shorter lease timeout. Setting a timeout of less than 5 minutes will force the cleanup of resources to happen faster, which can help avoid stranded resources and resource pressure.

Personal tools