Reputation: 2636
I'm new to Redis started playing with redis hashes to store some objects and I came across some very unexpected performance issues. I'm running redis on an Ubuntu machine that is hosted locally on vmware player.
my vm is two cores with 4 GB of memory.
heres the code I'm trying.
using (var redis = new RedisClient())
{
using (var client = redis.As<MyClass>())
{
var hash = client.GetHash<Guid>("urn:class");
var items = hash.Values;
}
}
the hash contains about 2000 items added from our entity model. To get all the Values out of the hash is taking 7 seconds during my runs which seems way to high even for the little bit of hardware that redis has in my instance. A normal LINQ to Entity query for the same data is taking .25 seconds.
Is there anything I'm doing wrong here? This just seems wrong considering all the great things I hear about redis performance.
Edit: 07/12/2013
This apperas to be a WCF issue. this post Using Redis to Scale Web Services basically mirrors my results. What I did to test was this.
Retrieve Redis hash with 1683 objects
Web Api and Node ran like a charm and ran close to what the times were when I ran redis-benchmark.
Upvotes: 1
Views: 1253
Reputation: 2636
My issue was with the class I was using as the context for the Redis client. The class was an entity model generated using the old version of the entity framework with Object Context. The way the entities were being generated was causing the ServiceStack.Redis client to have to do a ton of work to deserialize the objects coming back from Redis. The entities navigation property's set methods have calls to
InitializeRelatedCollection()
which were being called every time the json parser had to deserialize an object coming back through the Redis client. Switching to a simpler object without the navigation properties worked fine and brought the times back to numbers I expected in line with my other tests.
The reason I did not see this slow down in the ASP.NET Web API was because the entities were generated using the new DbContext model and the Json serializer in ServiceStack didn't have to do nearly the amount of work that it did in the WCF project because the navigation properties are just simple lists or collections.
It was probably not a great idea to make the entity object the type for the Redis client in the first place.
Upvotes: 1