当前位置:编程学习 > asp >>

asp.net Cache vs memcached

一、环境
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
 
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,