Is local cache being used here? Why such slow IEnumerable evaluation?
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
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()?
精彩评论