这里是否使用了本地缓存?为什么这么慢的IEnumerable求值
本文关键字:为什么 求值 IEnumerable 缓存 是否 这里 | 更新日期: 2023-09-27 17:53:11
在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>");
事件日志输出:
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 - 87 - d6 - 43 - bc - 8 ea5 - 667 - f072040d2
不确定,因为我不知道底层实现,但是. tolist()对我来说似乎很可疑。这将遍历整个枚举。有必要吗?直接去ToDictionary()怎么样?