檢查、剖析memcached運用狀況
訪問量上升,數據庫壓力大,怎樣辦?好辦法是在中心擋一層緩存!這個緩存需求高效,不能比數據庫慢,不然服務質量受影響;假如能把數據用hash打散存儲到硬盤,也是能夠的,不過在內存越來越廉價的今日,仍是運用內存吧!
mysql也有自個的緩存,也是存儲在內存的,但是有一個說法是:
以下是引證片段:
只能有一個實例
意味着你能存儲內容的上限即是你服務器的可用內存,一臺服務器能有多少內存?你又能存多少呢?
只需有寫操作,mysql的query cache就失效
只需數據庫內容稍有改動,那怕改動的是其他行,mysql的query cache也會失效
再說,假如mysql都抗不住了,怎樣還能盼望它供給的緩存呢?
所以我能夠運用memcached了!他的優點和如何用能夠參閱:
以下是引證片段:
1:《Memcache和mysql交互流程操作原理》
2:《讓memcached和mysql非常好的作業》
開發時面對需求是個麻煩事,更綿長而堵心的是維護,所以我更關心的是memcached運行中的狀況。還好的是,memcached的作者給咱們供給檢查運行狀況的指令。主要是“stats”,運用方法爲 “telnet ip 端口號”,登錄後運用“stats”指令。
然後你能夠看見很多內容,詳細能夠參閱:《memcacche stats》
以下是引證片段:
pid = process id
uptime = number of seconds since the process was started
time = current time
version = memcached version
rusage_user = seconds the cpu has devoted to the process as the user http://www.haomad.com
rusage_system = seconds the cpu has devoted to the process as the system http://www.metabase.cn
curr_items = total number of items currently in memcache
total_items = total number of items that have passed through the cache
bytes = total number of bytes currently in use by curr_items
curr_connections = total number of open connections to memcached
connection_structures = ???
cmd_get = total GET commands issued to the server
cmd_set = total SET commands issued to the server
get_hits = total number of times a GET command was able to retrieve and
return data
get_misses = total number of times a GET command was unable to retrieve and
return data
bytes_read = total number of bytes input into the server
bytes_written = total number of bytes written by the server
limit_maxbytes = total storage bytes available to the server.
着重說一下幾個對觀測很有用的項。