FreeBSD上mysql的效能追蹤

最近因為有台主機的 mysql cpu 異常變高許多, 所以要來進行查詢問題所在.

因為 mysql 沒有像 mssql 的 sql profiler 那麼方便的工具, 所以利用 mysql 本身的 log 來進行, 也就是 slow query log 這個功能, 步驟如下:

1. 先將 /etc/my.cnf 中的 [mysqld] 內多加入下面資料:

log-slow-queries = /var/log/slow-query.log #slow query記錄檔的位置
long_query_time = 2 #query執行超過2秒時才記錄

2. 重啟 mysql 服務, 指令如下:

/usr/local/etc/rc.d/mysql-server restart

3. 執行一陣子後, 就可以看看該 log 檔內的 query , 接下來就是針對這些 query 來調整效能

以上是在 FreeBSD 環境下的作法. (其他環境其實也類似)

其實執行時間長不一定是效率不好, 不過若是常常發生的查詢是需要長時間的, 就有改善的必要, 簡單地說, 就是若一個查詢需要 5秒, 但一天跑不到 10次, 那根本不用管他, 不過若一個查詢需要 0.02 秒, 但一天要用到數萬次, 即使從 0.02 改善到 0.015 就會有很明顯的效能改善, 所以要看發生的頻率及所花費執行的時間, 平衡來看.

另外, 若是該 log 沒有產出, 記得權限要給對, 因為是 mysql service account 去執行寫入的動作, 就算沒有任何 log 也會有 mysql 啟動的資訊, 不會沒有任何產出的 log.

參考資料:
http://dev.mysql.com/doc/refman/5.1/en/slow-query-log.html
http://blog.lansea-chu.com/index.php/archives/238
http://homeserver.com.tw/mysql/mysql%E7%9A%84%E6%9F%A5%E8%A9%A2%E6%99%82%E9%96%93log-slow-queries/
http://ezkuan.blogspot.com/2010/05/freebsd-mysql.html

分類
FreeBSD/Linux

ssh登入緩慢問題

最近的一次更新, 讓 FreeBSD 主機在登入時, 速度變得很慢, 這對操作上有蠻大的影響, 於是問了同事, 也著手進行查詢相關的可能, 原來是 OpenSSH 的名稱反查問題, 簡單處理方式如下:

修改 /etc/ssh/sshd_config 檔內的一個 UseDNS 參數, 設為 no 即可.

官方說明連結: http://www.openssh.org/faq.html#3.3

3.3 – ssh(1) takes a long time to connect or log in

 

Large delays (more that 10 seconds) are typically caused a problem with name resolution:

  • Some versions of glibc (notably glibc 2.1 shipped with Red Hat 6.1) can take a long time to resolve “IPv6 or IPv4” addresses from domain names. This can be worked around with by specifying AddressFamily inet option in ssh_config.
  • There may be a DNS lookup problem, either at the client or server. You can use the nslookup command to check this on both client and server by looking up the other end’s name and IP address. In addition, on the server look up the name returned by the client’s IP-name lookup. You can disable most of the server-side lookups by setting UseDNS no in sshd_config.

下面還有如何判定是 “slow”

CPU Time (SSHv1)[1] Time (SSHv2)
170MHz SPARC/sun4m 0.74 sec 1.25 sec
236MHz HPPA/8200[2] 0.44 sec 0.79 sec
375MHz PowerPC/604e 0.38 sec 0.51 sec
933MHz VIA Ezra 0.34 sec 0.44 sec
2.1GHz Athlon XP 2600+ 0.14 sec 0.22 sec

參考看看吧!

分類
FreeBSD/Linux

找指定檔案內容的語法

在 Linux, FreeBSD 下若要指定目錄以下的檔案內容查詢的指令, 可以利用 find 配合 -exec 參數, 再配合 grep 指令即可達到目的.

使用方式如下:

find . -name “*.log” -exec grep Virtual {} \;

這個方式就以 . 目錄以下, 找出所有 .log 的檔案, 內容有含 “Virtual” 的行內容, 但要注意最後方的 semicolon (分號) 要以反斜線開頭, 才會被 -exec 認識.

Exit mobile version