接着我们刷新memcache.aspx页面,页面上还显示上述信息:
通过读取缓存得到的数据:
姓名:lucy,密码:lucy
但从Sql Server Profiler观察,memcache.aspx页面没有对数据库进行任何操作。说明我们第二次访问该页面是读取的缓存,接着不停的刷新页面,都显示的是通过读取缓存得到的数据。直到到达缓存失效时间。
测试nomemcache.aspx,我们运行nomemcache.aspx页面,每刷新一次(包括第一次),Sql Server Profiler都记录了,nomemcache.aspx页面对数据库进行的操作,即之行了Select * From T_User Where id=2语句。说明每访问一次该页面,都要进行一次数据库的访问操作。
3.性能分析
Memcache.aspx的测试报告:
Overview
================================================================================
Report name: 2009-7-20 10:52:00
Run on: 2009-7-20 10:52:00
Run length: 00:01:12
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 2696
Requests per Second: 44.93
Socket Statistics
--------------------------------------------------------------------------------
Socket Connects: 3169
Total Bytes Sent (in KB): 646.80
Bytes Sent Rate (in KB/s): 10.78
Total Bytes Recv (in KB): 2019.37
Bytes Recv Rate (in KB/s): 33.65
Socket Errors
--------------------------------------------------------------------------------
Connect: 0
Send: 0
Recv: 0
Timeouts: 0
RDS Results
--------------------------------------------------------------------------------
Successful Queries: 0
Page Summary
Page Hits TTFB Avg TTLB Avg Auth Query
================================================================================
GET /WebMemCache/memcache.aspx 2696 1.94 1.95 No No
Nomemcache.aspx的测试报告:
Overview
================================================================================
Report name: 2009-7-20 10:54:01
Run on: 2009-7-20 10:54:01
Run length: 00:01:12
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 2577
Requests per Second: 42.95
Socket Statistics
--------------------------------------------------------------------------------
Socket Connects: 2860
Total Bytes Sent (in KB): 589.32
Bytes Sent Rate (in KB/s): 9.82
Total Bytes Recv (in KB): 1932.75
Bytes Recv Rate (in KB/s): 32.21
Socket Errors
--------------------------------------------------------------------------------
Connect: 0
Send: 0
Recv: 0
Timeouts: 0
RDS Results
--------------------------------------------------------------------------------
Successful Queries: 0
Page Summary
Page Hits TTFB Avg TTLB Avg Auth Query
================================================================================
GET /WebMemCache/nomemcache.aspx 2577 4.75 4.79 No No
从测试报告上看出memcache.aspx页面在一分钟内的Hits(命中次数)2696,平均TTFB是(Total Time to First Byte)1.94,平均TTLB(Total Time to Last Byte)是1.95。这些参数都低于nomemcache.aspx。另外memcache.aspx的Requests per Second(每秒请求的次数)是 44.93高于nomemcache.aspx页面的42.95.这些参数都说明memcache.aspx页面的执行性能要高于 nomemcache.aspx页面。缓存起到了提高性能的作用。当然我这里面进行的测试只是模拟500个用户在1分钟内的访问对Web服务器性能的影 响。 总结
本文简单介绍了Memcached的基本原理,特点以及工作方式,接下来介绍了 Windows下Memcached服务器端程序的安装方法、在.NET应用程序中使用.NET memcached client library。接下来通过运行分析程序来了解memcached的工作原理机制,最后通过压力测试工具对没有加入Memcached机制的页面和加入 Memcached页面进行了压力测试,对比加入Memcached机制前后Web应用程序的性能。了解Memcached内部构造, 就能知道如何在应用程序中使用memcached才能使Web应用的速度更上一层楼。提升web应用程序的性能和访问速度。