Mysql高性能之Memcached(1)_MySQL
本文将介绍Memcached的安装与使用 What is Memcached? Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages. Why Use Memcached? Benefits of using memcached include: ? Because all information is stored in RAM, the access speed is faster than loading the information each time from disk. ? Because the “value” portion of the key-value pair does not have any data type restrictions, you can cache data such as complex structures, documents, images, or a mixture of such things. ? If you use the in-memory cache to hold transient information, or as a read-only cache for information also stored in a database, the failure of any memcached server is not critical. For persistent data, you can fall back to an alternative lookup method using database queries, and reload the data into RAM on a different server. The typical usage environment is to modify your application so that information is read from the cache provided by memcached. If the information is not in memcached, then the data is loaded from the MySQL database and written into the cache so that future requests for the same object benefit from the cached data. Case: [root@ogg1 bin]# memcached -hmemcached 1.4.4-p初始化Memcached: memcached -u root -d -m 512 -p 11211 -l 192.168.56.12[root@ogg1 bin]# ps -ef |grep memroot 4382 1 0 02:01 ? 00:00:00 memcached -u root -d -m 512 -p 11211 -l 192.168.56.12查看当前Memcached的状态: [root@ogg1 bin]# telnet 192.168.56.12 11211 Trying 192.168.56.12...Connected to 192.168.56.12.Escape character is '^]'.statsSTAT pid 4382STAT uptime 7288STAT time 1418893354STAT version 1.4.4STAT pointer_size 64STAT rusage_user 0.353946STAT rusage_system 0.379942STAT curr_connections 5STAT total_connections 8STAT connection_structures 6STAT cmd_get 0STAT cmd_set 0STAT cmd_flush 0STAT get_hits 0STAT get_misses 0STAT delete_misses 0STAT delete_hits 0STAT incr_misses 0STAT incr_hits 0STAT decr_misses 0STAT decr_hits 0STAT cas_misses 0STAT cas_hits 0STAT cas_badval 0STAT auth_cmds 0STAT auth_errors 0STAT bytes_read 144STAT bytes_written 1732STAT limit_maxbytes 536870912STAT accepting_conns 1STAT listen_disabled_num 0STAT threads 4STAT conn_yields 0STAT bytes 0STAT curr_items 0STAT total_items 0STAT evictions 0END对应参数解释:pid memcache服务器的进程IDuptime 服务器已经运行的秒数time 服务器当前的unix时间戳version memcache版本pointer_size 当前操作系统的指针大小(32位系统一般是32bit)rusage_user 进程的累计用户时间rusage_system 进程的累计系统时间curr_items 服务器当前存储的items数量total_items 从服务器启动以后存储的items总数量bytes 当前服务器存储items占用的字节数curr_connections 当前打开着的连接数total_connections 从服务器启动以后曾经打开过的连接数connection_structures 服务器分配的连接构造数cmd_get get命令(获取)总请求次数cmd_set set命令(保存)总请求次数get_hits 总命中次数get_misses 总未命中次数evictions 为获取空闲内存而删除的items数(分配给memcache的空间用满后需要删除旧的items来得到空间分配给新的items)bytes_read 总读取字节数(请求字节数)bytes_written 总发送字节数(结果字节数)limit_maxbytes 分配给memcache的内存大小(字节)threads 当前线程数 |