欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net Cache vs memcached

程序员文章站 2022-07-05 23:30:41
一、环境 Server:IBM X365 M3 8Core 8G RAM OS:windows server 2008 r2 & Hyper-V+CentOS 6.2...
一、环境

Server:IBM X365 M3 8Core 8G RAM

OS:windows server 2008 r2 & Hyper-V+CentOS 6.2

二、代码

(1)主体代码,简单读取:

[csharp] 

SqlDataAdapter DataAdapter = new SqlDataAdapter();  

SqlConnection Conn = new SqlConnection(DataConn);  

Conn.Open();  

SqlCommand myCommand = new SqlCommand(sql, Conn);  

DataAdapter.SelectCommand = myCommand;  

DataAdapter.Fill(ds);  

Conn.Close()  

(2)Memcached(客户端:BeITMemcached)

[csharp]  

cache.SendReceiveTimeout = 5000;  

cache.MinPoolSize = 2;  

cache.MaxPoolSize = 5;          

string cached_dt = cache.Get(key) as string;  

if (cached_dt == null)  

 {  

    //主体代码  

    string str_dt = DataTableXml.SerializeDataTableXml(ds.Tables[0]);  

    cache.Set(key, str_dt, 30);  

 }  

else  

{  

    ds.Tables.Add(DataTableXml.DeserializeDataTable(cached_dt));  

}  

(3)Asp.net Cache

[csharp] view plaincopy

if (HttpContext.Current.Cache[key]==null)  

{  

    //主体代码  

    HttpContext.Current.Cache.Insert(key, ds, null, DateTime.Now.AddSeconds(30), System.Web.Caching.Cache.NoSlidingExpiration);  

}  

else  

{  

    ds = (DataSet)HttpContext.Current.Cache[key];  

}  

三、测试工具与参数

ab -t 30 -c 50 192.168.0.226/t.aspx

说明:t.aspx页面读取Dataset 24次,for(int i=1;i<=24;i++)

四、结果

(1)Memcached

Requests per second:    293.53 [#/sec] (mean)

Time per request:       170.343 [ms] (mean)

(2)Asp.net Cache

Requests per second:    2408.06 [#/sec] (mean)

Time per request:       20.764 [ms] (mean)

五、结论

Memcached可能在对象序列化及网络上相对LocalCache性能损耗大很多!

 

 

引用:

Cache Type                Cache Gets/sec

 

Array Cache                       365000

APC Cache                          98000

File Cache                         27000

Memcached Cache (TCP/IP)           12200

MySQL Query Cache (TCP/IP)          9900

MySQL Query Cache (Unix Socket)    13500

Selecting from table (TCP/IP)       5100

Selecting from table (Unix Socket)  7400