ChannelFactory创建和销毁昂贵

  1. involves内部创建ChannelFactory<T>,每个proxy都持有一个ChannelFacotry的private field。ChannelFactory的生命周期由proxy完全控制。

 

  • 构造ContractDescription树
  • 反射所有需要的CLR类型
  • 构造channel stack
  • dispose所有的资源

在3.0SP1和3.5下两个主要的性能提升:

  • ChannelFacotry缓存在ClientBase<T>里
  • Channel管理逻辑改进

改进:

核心:ClientBase<T>的性能提升依靠缓存ChannelFactory对象

ChannelFacotry的生命周期不在被proxy控制,使用MRU cache(most recently used)。cache size为32(固定的)

· In the constructor of ClientBase<T>, a lookup is performed to find amatched ChannelFactory in the cache.

· If found, the ref-count of the ChannelFactory is incremented. Otherwise, a new ChannelFactory is created based on the settings.

· Before the inner channel (the transparent proxy) of ClientBase<T> is created, the caching logic for the current ClientBase<T> can be disabled if other public properties (such as ChannelFactory, Endpoint, and ClientCredentials) are accessed.

· Once the innerchannel if created successfully, the ChannelFactory object for the ClientBase<T> is added to the cache if it’s not grabbed from the cache and caching is not disabled.

posted @ 2010-05-12 13:21  new 维生素C.net()  阅读(778)  评论(0编辑  收藏  举报