顯示具有 程式設計 標籤的文章。 顯示所有文章
顯示具有 程式設計 標籤的文章。 顯示所有文章

2012年7月27日 星期五

網站壓力測試工具 - Apache Benchmark(ab) 說明

ab指令的語法是 ab -c {同時進行的request數量} -n {次數} {url}


例如:
同時連線數: 100 人
ab -n  100 -c  100 http://xx.xx.xx.xx/index.php



C:\Apache\bin>ab -n 100 -c 100 http://192.168.1.103/index.php


This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.1.103 (be patient).....done


Server Software:        Apache
Server Hostname:        192.168.1.103
Server Port:            80

Document Path:          /index.php
Document Length:        2261 bytes

Concurrency Level:      100
Time taken for tests:   5.432 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      257300 bytes
HTML transferred:       226100 bytes
Requests per second:    18.41 [#/sec] (mean)
Time per request:       5432.000 [ms] (mean)
Time per request:       54.320 [ms] (mean, across all concurrent requests)
Transfer rate:          46.26 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        2    7  43.5      2     438
Processing:   292 2631 1352.8   2680    4916
Waiting:      289 2629 1352.9   2678    4915
Total:        295 2638 1348.1   2686    4918

Percentage of the requests served within a certain time (ms)
  50%   2686
  66%   3401
  75%   3733
  80%   3875
  90%   4534
  95%   4666
  98%   4720
  99%   4918
 100%   4918 (longest request)



後面的幾行粗體字資料是整個回應等候時間的統計,算是 Apache Benchmark 的數據價值精華所在。這些數據表示了這 100 個人所感受到的回應速度統計。以上面這個例子來說,此次執行結果顯示這次測試結果從 2.282 秒到 4.918 秒不等。 其中50%(50)的使用者感受的反應時間是 2.686 秒以下, 90%(90)的使用者感受的反應時間是 4.534 秒中以下,所有的人均在 4.918 秒內得到回應。

2012年7月23日 星期一

如何找到 MySQL 的瓶頸


Windows下開啟 MySQL 慢查詢
MySQL在Windows系統中的配置文件一般是是 my.ini 找到[mysqld]下面加上
log-slow-queries = C:\temp\mysqlslowquery.log
long_query_time = 3


Linux下啟用MySQL慢查詢
MySQL在Windows系統中的配置文件一般是是 /etc/my.cnf 找到[mysqld]下面加上
log-slow-queries=/tmp/slowquery.log
long_query_time=3

# service mysqld restart

然後看一下 /tmp/slowquery.log
看到慢查詢的 SQL
再看一下索引問題

如何在 MySQL中找到 SQL 瓶頸 - 利用 show profiles


寫資料庫程式時,常需要對 SQL 語法做效能調教,我發現 MySQL 的 profiling 還不錯。

1. 檢查是否有開啟 profiling 功能 (預設是關閉的)
mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
|           0 |
+-------------+
1 row in set (0.00 sec)

2. 開啟 profiling 功能
mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
|           1 |
+-------------+
1 row in set (0.00 sec)

3. 執行需要測試的 SQL
mysql> SELECT xxx FROM tbl WHERE id=123

4. 檢視效能資料
mysql> show profiles;

mysql> show profile for query 1;

5. 關閉 profiling 功能
mysql> set profiling=0;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@profiling;
+-------------+
| @@profiling |
+-------------+
|           0 |
+-------------+
1 row in set (0.00 sec)

2012年7月17日 星期二

公司網頁最好對各大搜尋引擎做一下最佳化


今天要連合作金庫銀行 eATM 時發生一件趣事,首先我上 Google 輸入「合作金庫 ATM」,Google 馬上找到,然後我直接連次項目的「合作金庫銀行eATM」,結果網頁出現「非IE瀏覽器使用者」。

只是我明明是使用 IE9,難道不支援新版 IE 9 嗎?後來仔細檢查才知道是 Google 搜尋的問題,但這應該算是合作金庫網頁設計的問題,因為 Google 針對合作金庫銀行網站建立的搜尋結果在「合作金庫銀行eATM」的連結判斷錯誤,Google 依據自身的演算法將「合作金庫銀行eATM」的連結網址設成「https://eatm.tcb-bank.com.tw/closePage.htm」,而這一網頁應該是在判斷使用者使用非 IE 連覽器後出現的錯誤網頁,現在卻變成 Google 搜尋結果「合作金庫銀行eATM」的連結網頁。

合庫的網頁開發者應該馬上去查一下,為何這一個錯誤訊息網頁的 Page rank 竟然高於應該正常出現的網頁(https://eatm.tcb-bank.com.tw/),不過這讓我學到一件事,就是以後不能太信任 Google 的搜尋結果。


如何用 php 存取 Google Apps Email


有申請 Google Apps 的人, 如果想要用php 去存取 mail server
過程如下:
...
$mbox = imap_open("{pop.gmail.com:995/imap/ssl/novalidate-cert}INBOX", $username, $password);
...

PS:
1. server 需要安裝 imap
    # yum install php-imap
    # /etc/rc.d/init.d/httpd restart

2. 其中 username 需要完整格式:
    如; $username  = "abc@xyz.com.tw";

3. 記得要在 Gmail 中 enabled pop3/imap
    https://mail.google.com/support/bin/answer.py?answer=13273