是否在这里使用本地缓存?为什么这么慢的IEnumerable评估呢?

时间:2011-04-27 18:35:55

标签: c# caching ienumerable appfabric

在EAV模式中使用约4600个对象,当序列化为单个集合时,总共约140,000个属性表示小于25 MB;不确定序列化时的确切大小,就像它们在这里一样,是4600个单独的缓存项目。

要解决EAV属性方案加载时间问题,我们尝试在启动时启动AppFabric,以及依靠本地缓存。但是,当我评估来自GetObjectsByTag或GetObjectsInRegion的IEnumerable时,我观察到一些非常糟糕的性能:

   var products = new Dictionary<string, ProductContract>();

   Trace.WriteLine(DateTime.Now.ToLongTimeString() + " retrieving object collection from cache");
   //object productsObj = _cache.Get(ProductCollectionNameInCache, this.CacheRegion);
   //var productsObjUneval = _cache.GetObjectsByTag(ProductCacheTag, this.CacheRegion);
   var productsObjUneval = _cache.GetObjectsInRegion(this.CacheRegion);
   Trace.WriteLine(DateTime.Now.ToLongTimeString() + " retrieving object collection from cache complete");

   Trace.WriteLine(DateTime.Now.ToLongTimeString() + " evaluating IEnumerable object");
   var productsObj = productsObjUneval.Where(p=>p.Key != ProductsPrimedFlagNameInCache).ToList();
   Trace.WriteLine(DateTime.Now.ToLongTimeString() + " end evaluating IEnumerable object");

   Trace.WriteLine(DateTime.Now.ToLongTimeString() + " converting object collection to Dictionary<string, ProductContract>");
   products = productsObj.ToDictionary(p => p.Key, p => (ProductContract) p.Value);
   Trace.WriteLine(DateTime.Now.ToLongTimeString() + " end converting object collection to Dictionary<string, ProductContract>");

EventLog输出:

Level   Date and Time   Source  Event ID    Task Category
Information 4/27/2011 12:55:22 PM   EPC Service 0   None    12:55:22 PM end getting products from cache
Information 4/27/2011 12:55:22 PM   EPC Service 0   None    12:55:22 PM end converting object collection to Dictionary<string, ProductContract>
Information 4/27/2011 12:55:22 PM   EPC Service 0   None    12:55:22 PM converting object collection to Dictionary<string, ProductContract>
Information 4/27/2011 12:55:22 PM   EPC Service 0   None    12:55:22 PM end evaluating IEnumerable object
Information 4/27/2011 12:55:05 PM   EPC Service 0   None    12:55:05 PM evaluating IEnumerable object
Information 4/27/2011 12:55:05 PM   EPC Service 0   None    12:55:05 PM retrieving object collection from cache complete
Information 4/27/2011 12:55:05 PM   EPC Service 0   None    12:55:05 PM retrieving object collection from cache
Information 4/27/2011 12:55:05 PM   EPC Service 0   None    12:55:05 PM getting products from cache
Information 4/27/2011 12:55:05 PM   EPC Service 0   None    12:55:05 PM is cache primed? True

编辑:按标签调用所有对象,还是区域内的所有对象,总是违反分布式缓存而不是本地?这将是非常令人失望的,对我们的需求完全没用。 http://social.msdn.microsoft.com/forums/en-us/velocity/thread/C0F1863A-87D6-43BC-8EA5-667F072040D2

1 个答案:

答案 0 :(得分:0)

不确定,因为我不知道底层实现,但.ToList()似乎对我很怀疑。这将完成整个枚举。有必要吗?那么直接去ToDictionary()?