Close Your Proxies
Hey! Call Close on your client proxy objects once you're done using them! This is always a good idea, but it's a tremendously good idea when using sessionful channels. Your client takes up resources on the server until you either close the proxy object or the server reaches the idle timeout for the connection. Resource usage on the server is bounded by server quotas that limit the number of outstanding sessions before additional clients get queued up. The garbage collector will close your proxies once it gets around to it but who knows how long in the future it will be before the garbage collector runs?
Having a well-written client allows you to pack more people on a single server without having to aggressively time out idle clients. Aggressive timeout values will disconnect poorly-written clients but will also disconnect clients that are just slow rather than idle. All you have to do is:
- Call Close on the proxy object if created from a nicely generated service proxy
Cast to IChannel and call Close on the proxy object if created from ChannelFactory.CreateChannel
Next time: Just the Headers
Comments
Anonymous
May 25, 2007
The following error is one that could be commonplace at any time during the last ten years. "SSPI negotiationAnonymous
May 25, 2007
Would this also be the case if we were using a transport like MSMQ? What if we have a large number of clients with flaky connections (say airports, conferences, etc) - might that become a scalability issue?Anonymous
May 25, 2007
MSMQ is asynchronous between the client and server, so while you may be tying up connections to the queue manager, the service doesn't see any of that.Anonymous
May 28, 2007
What about proxies used from web clients where the object only lives for the request response lifetime? Seen soome ppl pooling up their proxies for this use (http://weblogs.asp.net/pglavich/archive/2007/05/07/wcf-client-channel-pool-improved-client-performance.aspx) Also...any difference if you're using http vs tcp etc?Anonymous
May 28, 2007
In the case of pooling, you're not done using the proxy object until demand for the pool has gone idle and you have an excess of cached items. Once that happens, then you should call Close on the proxies being removed from the pool.