快速业务通道

.Net下的分布式缓存 - 分布式缓存同步的实现

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-04-11
003 sp1, Framework 2.0,T2060, 1G内存( 沙加的神舟笔记本;) ), 千兆网卡.
   两台机器通过直连线相连.
  
   .Net Cache单机测试 : P4 D 3.4G, 768MB 内存.
  
   测试结果, 存取10000个条目的时间:
  
   Memcached
   Set(秒) 1.48 1.37 1.48 1.37 1.46
   Get(秒) 2.42 2.42 2.42 2.43 2.42
  
   HttpRuntime.Cache
   Set(秒) 0.015 0.015 0.015 0.015 0.015
   Get(秒)
   0.015 0.015 0.015 0.015 0.015
  
  
   .Net内建缓存测试代码HttpRuntime.Cache
   protected void Page_Load(object sender, EventArgs e)
   {
   int start = 200;
   int runs = 10000;
  
   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 benchmarking recently";
  
   long begin = DateTime.Now.Ticks;
   for(int i = start; i < start+runs; i++)
   {
   HttpRuntime.Cache.Add(keyBase + i, obj,null,System.Web.Caching.Cache.NoAbsoluteExpiration,
   TimeSpan.FromMinutes(1),System.Web.Caching.CacheItemPriority.Normal,null);
   }
   long end = DateTime.Now.Ticks;
   long time = end - begin;
  
   Response.Write(runs + " sets: " + new TimeSpan(time).ToString() + "ms<br />");
  
   begin = DateTime.Now.Ticks;
   int hits = 0;
   int misses = 0;
   for(int i = start; i < start+runs; i++)
   {

 

 


   string str = (string) HttpRuntime.Cache.Get(keyBase + i);
   if(str != null)
   ++hits;
   else
   ++misses;
   }
   end = DateTime.Now.Ticks;
   time = end - begin;
  
   Response.Write(runs + " gets: " + new TimeSpan(time).ToString() + "ms");
   }
   Memcached测试代码Memcached
   namespace Memcached.MemcachedBench
   {
   using System;
   using System.Collections;
  
   using Memcached.ClientLibrary;
  
   public class MemcachedBench
   {
   [STAThread]
   public static void Main(String[] args)
   {
   int runs = 100;
   int start = 200;
   if(args.Length > 1)
   {
   runs = int.Parse(args[0]);
   start = int.Parse(args[1]);
   }
  
   string[] serverlist = { "140.192.34.72:11211", "140.192.34.73:11211" }

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号