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

发布于 2024-11-04 00:48:06 字数 2865 浏览 1 评论 0原文

在 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

Working with some ~4600 objects in an EAV schema with some 140,000 or so attributes total representing less than 25 MB when serialized as a single collection; not sure exactly how large when serialized, as they are here, as 4600 individual cached items.

To work around EAV attribute scheme load time issues, we're attempting to prime AppFabric on startup, as well as lean on the local cache. However, I'm observing some very poor performance when the IEnumerable from GetObjectsByTag or GetObjectsInRegion is evaluated:

   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 output:

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

Edit: do calls for all objects by tag, or all objects in region, ALWAYS go against the distributed cache rather than local? That would be very disappointing, and completely useless for our needs. http://social.msdn.microsoft.com/forums/en-us/velocity/thread/C0F1863A-87D6-43BC-8EA5-667F072040D2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红ご颜醉 2024-11-11 00:48:06

不确定,因为我不知道底层的实现,但 .ToList() 对我来说似乎很可疑。这将遍历整个枚举。有必要吗?直接进入 ToDictionary() 怎么样?

Not sure, since I don't know the underlying implementation, but .ToList() seems suspect to me. That will walk the entire enumeration. Is it necessary? What about just going directly to ToDictionary()?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文