.Net下的分布式缓存 - 分布式缓存同步的实现
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-04-11
; // initialize the pool for memcache servers SockIOPool pool = SockIOPool.GetInstance(); pool.SetServers(serverlist); pool.InitConnections = 3; pool.MinConnections = 3; pool.MaxConnections = 5; pool.SocketConnectTimeout = 1000; pool.SocketTimeout = 3000; pool.MaintenanceSleep = 30; pool.Failover = true; pool.Nagle = false; pool.Initialize(); MemcachedClient mc = new MemcachedClient(); mc.EnableCompression = false; string keyBase = "testKey"; string obj = "This is a test of an object blah blah es, serialization does not seem to slow things down so much. The gzip compression is horrible horrible performance, so we only use it for very large objects. I have not done any heavy benchma***ng recently"; long begin = DateTime.Now.Ticks; for(int i = start; i < start+runs; i++) { mc.Set(keyBase + i, obj); } long end = DateTime.Now.Ticks; long time = end - begin; Console.WriteLine(runs + " sets: " + new TimeSpan(time).ToString() + "ms"); begin = DateTime.Now.Ticks; int hits = 0; int misses = 0; for(int i = start; i < start+runs; i++) { string str = (string) mc.Get(keyBase + i); if(str != null) ++hits; else ++misses; } end = DateTime.Now.Ticks; time = end - begin; Console.WriteLine(runs + " gets: " + new TimeSpan(time).ToString() + "ms"); Console.WriteLine("Cache hits: " + hits.ToString()); Console.WriteLine("Cache misses: " + misses.ToString()); IDictionary stats = mc.Stats(); foreach(string key1 in stats.Keys) { Console.WriteLine(key1); Hashtable values = (Hashtable)stats[key1]; foreach(string key2 in values.Keys) { Console.WriteLine(key2 + ":" + values[key2]); } Console.WriteLine(); } SockIOPool.GetInstance().Shutdown(); } } }结论通过这个对比测试我们可以看出内建的Cache比使用Memcached要快出约130倍,但是从总体速度上来看并不慢,这两种方式可以在项目中有选择性地结合使用可以产生很棒的效果.并且Memcached可使用的内存数量要多得多,同时也可以做集群避免单点问题. |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于.Net下的分布式缓存 - 分布式缓存同步的实现的所有评论