-->

2013-07-30

memo:

http://www.ipa.go.jp/software/open/ossc/seika_1005_1.htmlhttp://www.ipa.go.jp/software/open/ossc/seika_1005_1.html

MySQL入門(教材本体)

netstat -atn
$ netstat --help 2>&1 |grep -P "\-[atn]\W"
        -n, --numeric            don't resolve names
        -a, --all, --listening   display all sockets (default: connected)
  ={-t|--tcp} {-u|--udp} {-U|--udplite} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom

$ netstat -an | grep -iP ":3306\s"
tcp        0      0 192.168.0.110:3306      0.0.0.0:*               LISTEN

テスト。
http://www.php.net/manual/ja/function.socket-listen.php
$ (php -r '$sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);socket_bind($sock,"127.0.0.1",13579);socket_listen($sock);sleep(5);print "### PHP END!!\n";' &) && for sec in $(seq 1 10); do netstat -an | grep -iP ":13579\s"; sleep 1; echo sec=$sec; done
sec=1
tcp        0      0 127.0.0.1:13579         0.0.0.0:*               LISTEN
sec=2
tcp        0      0 127.0.0.1:13579         0.0.0.0:*               LISTEN
sec=3
tcp        0      0 127.0.0.1:13579         0.0.0.0:*               LISTEN
sec=4
tcp        0      0 127.0.0.1:13579         0.0.0.0:*               LISTEN
### PHP END!!
sec=5
sec=6
sec=7
sec=8
sec=9
sec=10

似ている。
mysql> SHOW CREATE TABLE mysql.time_zone\G
*************************** 1. row ***************************
       Table: time_zone
Create Table: CREATE TABLE `time_zone` (
  `Time_zone_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `Use_leap_seconds` enum('Y','N') NOT NULL DEFAULT 'N',
  PRIMARY KEY (`Time_zone_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1731 DEFAULT CHARSET=utf8 COMMENT='Time zones'
1 row in set (0.01 sec)

mysql> DESCRIBE mysql.time_zone;
+------------------+------------------+------+-----+---------+----------------+
| Field            | Type             | Null | Key | Default | Extra          |
+------------------+------------------+------+-----+---------+----------------+
| Time_zone_id     | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| Use_leap_seconds | enum('Y','N')    | NO   |     | N       |                |
+------------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

似ている。
mysql> SELECT DATABASE()\G
*************************** 1. row ***************************
DATABASE(): test
1 row in set (0.00 sec)

mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.1.70, for pc-linux-gnu (x86_64) using readline 5.1

Connection id:          102667
Current database:       test
Current user:           root@localhost
SSL:                    Not in use
...


2013-07-29

memo: mysql-proxy

*** glibc detected *** /usr/bin/mysql-proxy: corrupted double-linked list: 0x00000000023727e0 ***

$ tail -n10000 /var/log/mysql/mysql-proxy.log | perl -pe 's/^\S+ \S+:/:/' | perl -pe 's/ PID=\d+ died on signal=\d+ \(it used \d+ kBytes max\)/ PID=xxx died on signal=xxx (it used xxx kBytes max)/' | perl -pe 's/ Epoll ADD\(1\) on fd \d+ failed\./ Epoll ADD(1) on fd xxx failed./' | sort | uniq -c | sort -k1n
      2 : (critical) chassis-mainloop.c:267: applying config of plugin proxy failed
      2 : (critical) mysql-proxy-cli.c:595: Failure from chassis_mainloop. Shutting down.
      2 : (critical) network-socket.c:401: bind(127.0.0.1:4040) failed: Address already in use (98)
      2 : (warning) (libevent) Epoll ADD(1) on fd xxx failed.  Old events were 0; read change was 1 (add); write change was 0 (none): Bad file descriptor
     12 : (critical) chassis-unix-daemon.c:189: [angel] PID=xxx died on signal=xxx (it used xxx kBytes max) ... waiting 3min before restart
     18 : (critical) last message repeated 1 times
    295 : (warning) last message repeated 101 times
    302 : (warning) (libevent) event_del: event has no event_base set.
   4682 : (critical) proxy-plugin.c.1127: I have no server backend, closing connection
   4683 : (critical) network-mysqld.c.1414: plugin_call(CON_STATE_READ_QUERY) failed

$ /usr/bin/sudo /usr/bin/rcsdiff /etc/config-archive/etc/mysql/mysql-proxy.cnf,v /etc/mysql/mysql-proxy.cnf
===================================================================
RCS file: /etc/config-archive/etc/mysql/mysql-proxy.cnf,v
retrieving revision 1.3
diff -r1.3 /etc/mysql/mysql-proxy.cnf
8c8
< event-threads = 3
---
> event-threads = 1
16c16
< max-open-files = 8192
---
> max-open-files = 2048

$ ps aux|grep mysql-p|grep -v "[g]rep"
root     29174  0.0  0.0  35952   512 ?        S    06:34   0:00 /usr/bin/mysql-proxy --daemon --pid-file=/var/run/mysql-proxy.pid --defaults-file=/etc/mysql/mysql-proxy.cnf
root     29175 25.3  0.0  38688  4368 ?        S    06:34   1:15 /usr/bin/mysql-proxy --daemon --pid-file=/var/run/mysql-proxy.pid --defaults-file=/etc/mysql/mysql-proxy.cnf

$ pstree -p |grep mysql-p
        |-mysql-proxy(29174)---mysql-proxy(29175)

$ sudo grep proxy-lua-script /etc/mysql/mysql-proxy.cnf
proxy-lua-script = /etc/mysql/tutorial-keepalive.lua

$ bunzip2 -c /usr/share/doc/mysql-proxy-0.8.2/examples/tutorial-keepalive.lua.bz2 > tutorial-keepalive.lua.orig

$ diff tutorial-keepalive.lua.orig /etc/mysql/tutorial-keepalive.lua
37,38c37,38
< local min_idle_connections = 4
< local max_idle_connections = 8
---
> local min_idle_connections = 16
> local max_idle_connections = 80
41c41
< local is_debug = true
---
> local is_debug = false

http://dev.mysql.com/doc/refman/5.0/en/mysql-proxy-configuration.html#option_mysql-proxy_keepalive
MALLOC_CHECK_
http://www.flateight.com/modules/popnupblog/index.php?postid=1633
http://ruby-gnome2.sourceforge.jp/ja/hiki.cgihttp:/sfmltoj.cgi?key=/mailarchive/message.php%3Fmsg_id%3D8110724
http://www.ipa.go.jp/security/awareness/vendor/programmingv2/contents/c904.html

$ rcsdiff /etc/config-archive/etc/conf.d/mysql-proxy,v /etc/conf.d/mysql-proxy
===================================================================
RCS file: /etc/config-archive/etc/conf.d/mysql-proxy,v
retrieving revision 1.1
diff -r1.1 /etc/conf.d/mysql-proxy
12a13,14
>
> MALLOC_CHECK_=3

2013-07-27

htmlタグをエスケープするコマンド

$ cat html3.txt
<html>
 <head>
  <title>"test"</title>
 </head>
</html>

$ cat html3.txt | perl -pe 's/([<>&])/{"<","&lt;",">","&gt;","&","&amp;"}->{$1}/ge'
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;"test"&lt;/title&gt;
 &lt;/head&gt;
&lt;/html&gt;

$ cat html3.txt | php -r 'print htmlspecialchars(file_get_contents("php://stdin"));'
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;&quot;test&quot;&lt;/title&gt;
 &lt;/head&gt;
&lt;/html&gt;

コマンドのショートカット。
$ which htmlescape
which: no htmlescape in (/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3:/usr/x86_64-pc-linux-gnu/powerpc-unknown-linux-gnu/gcc-bin/4.5.4)

$ unalias htmlescape
bash: unalias: htmlescape: 見つかりません

$ htmlescape(){ php -r 'print htmlspecialchars(file_get_contents("php://stdin"));'; }

$ cat html3.txt | htmlescape
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;&quot;test&quot;&lt;/title&gt;
 &lt;/head&gt;
&lt;/html&gt;

http://d.hatena.ne.jp/tanakaBox/20070729/1185709167
http://d.hatena.ne.jp/n9d/20090106/1231237069
http://php.net/manual/ja/function.htmlspecialchars.php
htmlescape(){ read -rd '' s; echo "$s" | perl -pe 's/([<>&\"'\''])/{"<","&lt;",">","&gt;","&","&amp;","\"","&quot;","'\''","&#039;"}->{$1}/ge';}

<pre>の中に<br />

Bloggerで、複数の<br />が<pre>~</pre>に入ることがある。

A < B

1
2
3

A < B
1
2
3

前半の<pre>~</pre>に<br />が追加される。
A < B
<pre><br />
1<br />
2<br />
3<br />
</pre><br />
A &lt; B<br />
<pre>1
2
3
</pre><br />

対策はエスケープを手動でする。「A < B」の部分。
A < B
<pre>
1
2
3
</pre>

A &lt; B
<pre>
1
2
3
</pre>

memo: mysql-proxy: proxy-lua-script

設定ファイル修正。
$ /usr/bin/sudo /usr/bin/rcsdiff /etc/config-archive/etc/mysql/mysql-proxy.cnf,v /etc/mysql/mysql-proxy.cnf
===================================================================
RCS file: /etc/config-archive/etc/mysql/mysql-proxy.cnf,v
retrieving revision 1.1
diff -r1.1 /etc/mysql/mysql-proxy.cnf
8c8
< #event-threads = ...
---
> event-threads = 3
16c16
< #max-open-files = ...
---
> max-open-files = 8192
33c33
< proxy-backend-addresses = 127.0.0.1:3306
---
> proxy-backend-addresses = 192.168.0.110:3306
35c35
< #proxy-lua-script = ...
---
> proxy-lua-script = /tmp/tutorial-keepalive.lua

lua-scriptファイル修正。
$ qlist mysql-proxy|grep -i tutorial-keepalive
/usr/share/doc/mysql-proxy-0.8.2/examples/tutorial-keepalive.lua.bz2
$ diff tutorial-keepalive.lua.orig tutorial-keepalive.lua
37,38c37,38
< local min_idle_connections = 4
< local max_idle_connections = 8
---
> local min_idle_connections = 40
> local max_idle_connections = 80

mysql, apache再起動。
sudo /etc/init.d/mysql-proxy stop && sudo /etc/init.d/mysql restart && sudo /etc/init.d/apache2 restart

手動で起動。ログを見る場合。
$ sudo /usr/bin/mysql-proxy --defaults-file=/etc/mysql/mysql-proxy.cnf

abコマンド。
(for CNT in $(seq 1 3); do for PERSISTENT in 0 1; do for DSN in 1 2; do for C in 5000; do \
N=`expr ${C} \* 5` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}&persistent=${PERSISTENT}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
mysqladmin status && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
ps aux|grep -iP "^apache\s" | wc -l && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP -e "SELECT COUNT(*) FROM information_schema.PROCESSLIST WHERE Command='Sleep';" && \
sleep 60 && echo "### END"; \
done; done; done; done;)

4パターン。pconnect有り無し×(mysqlTCP接続 or mysql-proxy経由)×3回。
同時接続数が多すぎて mysqlTCP接続+pconnect < mysqlTCP接続+connect になった。
pconnect無し+mysql-proxy経由が目的で80の持続的接続になった。
$ (for CNT in $(seq 1 3); do for PERSISTENT in 0 1; do for DSN in 1 2; do for C in 5000; do \
> N=`expr ${C} \* 5` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}&persistent=${PERSISTENT}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && \
sleep 60 && echo "### END"; \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> mysqladmin status && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> ps aux|grep -iP "^apache\s" | wc -l && \
> echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && \
> mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP -e "SELECT COUNT(*) FROM information_schema.PROCESSLIST WHERE Command='Sleep';" && \
> sleep 60 && echo "### END"; \
> done; done; done; done;)

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
Complete requests:      25000
Requests per second:    2660.93 [#/sec] (mean)

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
25071 200

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
Uptime: 32  Threads: 2  Questions: 100286  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 3133.937

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
153

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-45-51-064473; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
Complete requests:      25000
Requests per second:    683.66 [#/sec] (mean)

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
25000 200

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
Uptime: 129  Threads: 79  Questions: 275213  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 2133.434

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
251

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-47-00-895929; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|       77 |
+----------+
### END

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
Complete requests:      25000
Requests per second:    1055.95 [#/sec] (mean)

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
25029 200

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
Uptime: 213  Threads: 252  Questions: 325275  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1527.112

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
251

===== CNT=1; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-48-37-890069; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      250 |
+----------+
### END

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
Complete requests:      25000
Requests per second:    808.57 [#/sec] (mean)

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
24934 200
66 505

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
Uptime: 305  Threads: 206  Questions: 449742  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1474.563

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
251

===== CNT=1; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-50-01-989929; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      204 |
+----------+
### END

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
Complete requests:      25000
Requests per second:    2500.22 [#/sec] (mean)

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
25122 200

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
Uptime: 375  Threads: 2  Questions: 550234  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1467.290

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
251

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-51-33-325356; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
Complete requests:      25000
Requests per second:    542.38 [#/sec] (mean)

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
25000 200

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
Uptime: 482  Threads: 82  Questions: 725122  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1504.402

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
251

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-52-43-728182; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|       80 |
+----------+
### END

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
Complete requests:      25000
Requests per second:    1048.18 [#/sec] (mean)

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
25113 200

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
Uptime: 566  Threads: 252  Questions: 775360  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1369.893

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
251

===== CNT=2; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-54-30-261878; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      250 |
+----------+
### END

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
Complete requests:      25000
Requests per second:    806.09 [#/sec] (mean)

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
24760 200
241 505

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
Uptime: 657  Threads: 207  Questions: 898991  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1368.327

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
251

===== CNT=2; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-55-54-557779; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      205 |
+----------+
### END

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
Complete requests:      25000
Requests per second:    2492.24 [#/sec] (mean)

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
25009 200

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
Uptime: 728  Threads: 2  Questions: 999031  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1372.295

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
250

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-20-57-25-978648; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
Complete requests:      25000
Requests per second:    573.13 [#/sec] (mean)

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
25000 200

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
Uptime: 832  Threads: 74  Questions: 1174607  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1411.787

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
248

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-20-58-36-410075; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|       72 |
+----------+
### END

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
Complete requests:      25000
Requests per second:    1049.59 [#/sec] (mean)

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
25075 200

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
Uptime: 916  Threads: 236  Questions: 1224876  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1337.200

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
241

===== CNT=3; DSN=1; C=5000; N=25000; DATE=2013-07-27-21-00-20-465833; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      234 |
+----------+
### END

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
Complete requests:      25000
Requests per second:    792.33 [#/sec] (mean)

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
24860 200
140 505

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
Uptime: 1008  Threads: 215  Questions: 1349025  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1338.318

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
249

===== CNT=3; DSN=2; C=5000; N=25000; DATE=2013-07-27-21-01-44-72261; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|      213 |
+----------+
### END

pconnectは同時接続数の見積もりがうまくいくと性能を発揮する。
$ (for CNT in $(seq 1 2); do for PERSISTENT in 0 1; do for DSN in 1; do for C in 250; do N=`expr ${C} \* 20` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}&persistent=${PERSISTENT}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && mysqladmin status && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && ps aux|grep -iP "^apache\s" | wc -l && echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE}; PERSISTENT=${PERSISTENT}" && mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP -e "SELECT COUNT(*) FROM information_schema.PROCESSLIST WHERE Command='Sleep';" && sleep 0 && echo "### END"; done; done; done; done;)

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
Complete requests:      5000
Requests per second:    3311.34 [#/sec] (mean)

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
   5000 200

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
Uptime: 8  Threads: 1  Questions: 20001  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 2500.125

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
9

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-32-828484; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
Complete requests:      5000
Requests per second:    4135.26 [#/sec] (mean)

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
   5000 200

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
Uptime: 10  Threads: 7  Questions: 30011  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 3001.100

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
7

===== CNT=1; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-34-664255; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|        6 |
+----------+
### END

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
Complete requests:      5000
Requests per second:    1737.66 [#/sec] (mean)

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
   5000 200

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
Uptime: 13  Threads: 1  Questions: 50021  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 3847.769

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
7

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-36-192441; PERSISTENT=0
+----------+
| COUNT(*) |
+----------+
|        0 |
+----------+
### END

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
Complete requests:      5000
Requests per second:    3733.68 [#/sec] (mean)

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
   5001 200

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
Uptime: 15  Threads: 13  Questions: 60029  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 4001.933

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
13

===== CNT=2; DSN=1; C=250; N=5000; DATE=2013-07-27-21-22-39-404455; PERSISTENT=1
+----------+
| COUNT(*) |
+----------+
|       12 |
+----------+
### END

abコマンドに設定したスクリプト。
$ cat ab.php | perl -pe 's/([<>&])/{"<","<",">",">","&","&"}->{$1}/ge'
<?php
error_reporting(E_ALL|E_STRICT);
set_time_limit(0);

MAIN();
exit;

function MAIN()
{
    $dsn = isset($_GET["dsn"]) ? (int)$_GET["dsn"] : 1;
    $persistent = isset($_GET["persistent"]) ? (bool)$_GET["persistent"] : false;

    $server = "";
    $username = "";
    $password = "";
    switch ($dsn)
    {
    case 2:
        $server = "127.0.0.1:4040";
        $username = "test";
        $password = "test";
        break;
    case 1:
    default:
        $server = "192.168.0.110:3306";
        $username = "test";
        $password = "test";
        break;
    }

    $mysqlConnectFunc = $persistent ? "mysql_pconnect" : "mysql_connect";
    $link = $mysqlConnectFunc($server, $username, $password);
    if (!is_resource($link))
    {
        header('HTTP', true, 504);
        trigger_error(sprintf("mysql_pconnect error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }

    $result = mysql_query("SHOW FULL PROCESSLIST;", $link);
    if (!is_resource($result))
    {
        header('HTTP', true, 505);
        var_dump($result);
        trigger_error(sprintf("mysql_query error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }
    $num = mysql_num_rows($result);

    print "\$server: " . htmlspecialchars($server) . "<br />\n";
    print "\$username: " . htmlspecialchars($username) . "<br />\n";
    print "\$password: " . htmlspecialchars($password) . "<br />\n";

    print "number of lines: " . htmlspecialchars($num) . "<br />\n";
    print "<table border=1 style=\"empty-cells: show;\">\n";

    $cnt = 0;
    while ($row = mysql_fetch_assoc($result))
    {
        $cnt++;
        if ($cnt == 1)
        {
            print "<tr>\n";
            foreach ($row as $key => $val)
            {
                print "<th>" . htmlspecialchars($key) . "</th>\n";
            }
            print "</tr>\n";
        }

        print "<tr>\n";
        foreach ($row as $key => $val)
        {
            print "<td>" . htmlspecialchars($val) . "</td>\n";
        }
        print "</tr>\n";
    }
    print "</table>\n";

    mysql_free_result($result);

    $result = mysql_query("SET wait_timeout=30;");
    if (!is_resource($result) && $result != true)
    {
        header('HTTP', true, 505);
        var_dump($result);
        trigger_error(sprintf("mysql_query error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }
}

memo: mysql-proxy

$ grep -nri mysql-proxy /etc/portage/
/etc/portage/package.keywords/x86_64-pc-linux-gnu:16:=dev-db/mysql-proxy-0.8.2 ~amd64
/etc/portage/package.use/x86_64-pc-linux-gnu:14:dev-db/mysql-proxy              examples

sudo emerge --oneshot -avt mysql-proxy

$ emerge -pv mysql-proxy

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ~] dev-db/mysql-proxy-0.8.2  USE="examples" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

$ mysql -uroot -p -hlocalhost -P 4040 --protocol=TCP
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)

$ sudo /etc/init.d/mysql-proxy start

$ mysql -uroot -p -hlocalhost -P 4040 --protocol=TCP
Enter password:
ERROR 1105 (HY000): (proxy) all backends are down

$ netstat -an | grep 3306
tcp        0      0 192.168.0.110:3306      0.0.0.0:*               LISTEN
tcp        0      0 192.168.0.110:45661     192.168.0.110:3306      TIME_WAIT

$ mysql -uroot -p -h192.168.0.110 -P 3306 --protocol=TCP
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

$ mysql -uroot -p -h192.168.0.110 -P 4040 --protocol=TCP
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.110' (111)

http://docs.oracle.com/cd/E17952_01/refman-5.0-en/mysql-proxy-faq.html#qandaitem-16-7-6-1-2

$ /usr/bin/sudo /usr/bin/rcsdiff /etc/config-archive/etc/mysql/mysql-proxy.cnf,v /etc/mysql/mysql-proxy.cnf
===================================================================
RCS file: /etc/config-archive/etc/mysql/mysql-proxy.cnf,v
retrieving revision 1.1
diff -r1.1 /etc/mysql/mysql-proxy.cnf
33c33
< proxy-backend-addresses = 127.0.0.1:3306
---
> proxy-backend-addresses = 192.168.0.110:3306

$ sudo /etc/init.d/mysql-proxy restart

$ sudo grep proxy-address /etc/mysql/mysql-proxy.cnf
proxy-address = 127.0.0.1:4040

$ mysql -uroot -p -h127.0.0.1 -P 4040 --protocol=TCP
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.

mysql> GRANT SELECT ON test.* TO test@'%' IDENTIFIED BY 'test';
mysql> FLUSH PRIVILEGES;

$ mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP
ERROR 1045 (28000): Access denied for user 'test'@'vmware-gentoo1' (using password: YES)

mysql> GRANT SELECT ON test.* TO test@'vmware-gentoo1' IDENTIFIED BY 'test';
mysql> FLUSH PRIVILEGES;

$ mysql -utest -ptest -h192.168.0.110 -P 3306 --protocol=TCP
Welcome to the MySQL monitor.  Commands end with ; or \g.

$ mysql -utest -ptest -h127.0.0.1 -P 4040 --protocol=TCP
Welcome to the MySQL monitor.  Commands end with ; or \g.

$ php -r 'var_dump(mysql_connect("192.168.0.110","test","test"));'
resource(4) of type (mysql link)

$ php -r 'var_dump(mysql_connect("192.168.0.110","test","testxxx"));'
PHP Warning:  mysql_connect(): Access denied for user 'test'@'vmware-gentoo1' (using password: YES) in Command line code on line 1

$ php -r 'var_dump(mysql_connect("127.0.0.1:4040","test","test"));'
resource(4) of type (mysql link)

$ ab -n 1000 -c 100 "http://192.168.0.110/test/ab.php?dsn=2" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):"
Complete requests:      1000
Requests per second:    2253.65 [#/sec] (mean)

$ ab -n 1000 -c 100 "http://192.168.0.110/test/ab.php?dsn=1" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):"
Complete requests:      1000
Requests per second:    3483.41 [#/sec] (mean)

$ ulimit -n
1024

$ rcsdiff /etc/config-archive/etc/security/limits.conf,v /etc/security/limits.conf
===================================================================
RCS file: /etc/config-archive/etc/security/limits.conf,v
retrieving revision 1.1
diff -r1.1 /etc/security/limits.conf
48a49,50
> UserNameToRunTheBenchmarksOfApache soft nofile 8192
> UserNameToRunTheBenchmarksOfApache hard nofile 8192

soft => デフォルト値、hard => 最大値。
再度ログインで変更反映。

$ ulimit -n
8192

$ ab -n 50000 -c 5000 "http://192.168.0.110/test/ab.php?dsn=1" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):"
Complete requests:      50000
Requests per second:    2240.82 [#/sec] (mean)

$ ab -n 50000 -c 5000 "http://192.168.0.110/test/ab.php?dsn=2" 2>&1
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.0.110 (be patient)
Completed 5000 requests
Completed 10000 requests
apr_socket_recv: Connection reset by peer (104)
Total of 14923 requests completed

$ ab -n 50000 -c 5000 "http://192.168.0.110/test/ab.php?dsn=2" 2>&1
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.0.110 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
apr_socket_recv: Connection reset by peer (104)
Total of 22536 requests completed

http://dev.mysql.com/doc/refman/5.0/en/mysql-proxy-configuration.html#option_mysql-proxy_event-threads

$ /usr/bin/sudo /usr/bin/rcsdiff /etc/config-archive/etc/mysql/mysql-proxy.cnf,v /etc/mysql/mysql-proxy.cnf
===================================================================
RCS file: /etc/config-archive/etc/mysql/mysql-proxy.cnf,v
retrieving revision 1.1
diff -r1.1 /etc/mysql/mysql-proxy.cnf
8c8
< #event-threads = ...
---
> event-threads = 3
16c16
< #max-open-files = ...
---
> max-open-files = 8192
33c33
< proxy-backend-addresses = 127.0.0.1:3306
---
> proxy-backend-addresses = 192.168.0.110:3306

$ ab -n 50000 -c 5000 "http://192.168.0.110/test/ab.php?dsn=2" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):"
Complete requests:      50000
Requests per second:    1732.69 [#/sec] (mean)

sudo /etc/init.d/mysql restart && sudo /etc/init.d/mysql-proxy restart && sudo /etc/init.d/apache2 restart

(for CNT in $(seq 1 1); do for DSN in 1 2; do for C in 100 1000 5000; do \
N=`expr ${C} \* 10` && DATE=`php -r 'print preg_replace("/^0\.(.*?)0* (.*)$/e","date(\"Y-m-d-H-i-s-\",$2).\"$1\"",microtime());'` && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE};" && \
ab -n ${N} -c ${C} "http://192.168.0.110/test/ab.php?dsn=${DSN}&xxx=${DATE}" 2>&1 | grep -iP "^((Complete requests)|(Requests per second)):" && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE};" && \
grep xxx=${DATE} /var/log/apache2/access_log | awk '{print $9}' | sort | uniq -c && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE};" && \
mysqladmin status && \
echo && echo "===== CNT=${CNT}; DSN=${DSN}; C=${C}; N=${N}; DATE=${DATE};" && \
ps aux|grep -iP "^apache\s" | wc -l; \
done; done; done;) > /tmp/ab.txt

$ cat ab.php | perl -pe 's/([<>&])/{"<","<",">",">","&","&"}->{$1}/ge'
<?php
error_reporting(E_ALL|E_STRICT);
set_time_limit(0);

MAIN();
exit;

function MAIN()
{
    $dsn = isset($_GET["dsn"]) ? (int)$_GET["dsn"] : 1;

    $server = "";
    $username = "";
    $password = "";
    switch ($dsn)
    {
    case 2:
        $server = "127.0.0.1:4040";
        $username = "test";
        $password = "test";
        break;
    case 1:
    default:
        $server = "192.168.0.110:3306";
        $username = "test";
        $password = "test";
        break;
    }

    $link = mysql_pconnect($server, $username, $password);
    if (!is_resource($link))
    {
        header('HTTP', true, 504);
        trigger_error(sprintf("mysql_pconnect error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }

    $result = mysql_query("SHOW FULL PROCESSLIST;", $link);
    if (!is_resource($result))
    {
        header('HTTP', true, 505);
        var_dump($result);
        trigger_error(sprintf("mysql_query error. [%s] %s", mysql_errno(), mysql_error()), E_USER_ERROR);
    }
    $num = mysql_num_rows($result);

    print "\$server: " . htmlspecialchars($server) . "<br />\n";
    print "\$username: " . htmlspecialchars($username) . "<br />\n";
    print "\$password: " . htmlspecialchars($password) . "<br />\n";

    print "number of lines: " . htmlspecialchars($num) . "<br />\n";
    print "<table border=1 style=\"empty-cells: show;\">\n";

    $cnt = 0;
    while ($row = mysql_fetch_assoc($result))
    {
        $cnt++;
        if ($cnt == 1)
        {
            print "<tr>\n";
            foreach ($row as $key => $val)
            {
                print "<th>" . htmlspecialchars($key) . "</th>\n";
            }
            print "</tr>\n";
        }

        print "<tr>\n";
        foreach ($row as $key => $val)
        {
            print "<td>" . htmlspecialchars($val) . "</td>\n";
        }
        print "</tr>\n";
    }
    print "</table>\n";

    mysql_free_result($result);
}

$ grep -B1 Threads /tmp/ab.txt
===== CNT=1; DSN=1; C=100; N=1000; DATE=2013-07-27-14-20-29-145301;
Uptime: 10  Threads: 6  Questions: 1001  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 100.100
--
===== CNT=1; DSN=1; C=1000; N=10000; DATE=2013-07-27-14-20-29-547357;
Uptime: 13  Threads: 5  Questions: 11010  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 846.923
--
===== CNT=1; DSN=1; C=5000; N=50000; DATE=2013-07-27-14-20-32-932006;
Uptime: 52  Threads: 251  Questions: 61078  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1174.576
--
===== CNT=1; DSN=2; C=100; N=1000; DATE=2013-07-27-14-21-11-355416;
Uptime: 54  Threads: 501  Questions: 62079  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1149.611
--
===== CNT=1; DSN=2; C=1000; N=10000; DATE=2013-07-27-14-21-13-197702;
Uptime: 69  Threads: 501  Questions: 72095  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1044.855
--
===== CNT=1; DSN=2; C=5000; N=50000; DATE=2013-07-27-14-21-28-597448;
Uptime: 122  Threads: 249  Questions: 122100  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1000.819

http://dev.mysql.com/doc/refman/4.1/ja/gone-away.html

$ grep -B2 "Requests per second" /tmp/ab.txt
===== CNT=1; DSN=1; C=100; N=1000; DATE=2013-07-27-14-20-29-145301;
Complete requests:      1000
Requests per second:    4871.13 [#/sec] (mean)
--
===== CNT=1; DSN=1; C=1000; N=10000; DATE=2013-07-27-14-20-29-547357;
Complete requests:      10000
Requests per second:    3195.77 [#/sec] (mean)
--
===== CNT=1; DSN=1; C=5000; N=50000; DATE=2013-07-27-14-20-32-932006;
Complete requests:      50000
Requests per second:    1314.47 [#/sec] (mean)
--
===== CNT=1; DSN=2; C=100; N=1000; DATE=2013-07-27-14-21-11-355416;
Complete requests:      1000
Requests per second:    631.75 [#/sec] (mean)
--
===== CNT=1; DSN=2; C=1000; N=10000; DATE=2013-07-27-14-21-13-197702;
Complete requests:      10000
Requests per second:    661.34 [#/sec] (mean)
--
===== CNT=1; DSN=2; C=5000; N=50000; DATE=2013-07-27-14-21-28-597448;
Complete requests:      50000
Requests per second:    953.87 [#/sec] (mean)

$ grep -B1 Threads /tmp/ab.txt
===== CNT=1; DSN=2; C=100; N=1000; DATE=2013-07-27-14-30-51-109835;
Uptime: 16  Threads: 6  Questions: 1001  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 62.562
--
===== CNT=1; DSN=2; C=1000; N=10000; DATE=2013-07-27-14-30-51-680217;
Uptime: 20  Threads: 13  Questions: 11010  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 550.500
--
===== CNT=1; DSN=2; C=5000; N=50000; DATE=2013-07-27-14-30-55-454527;
Uptime: 61  Threads: 251  Questions: 61015  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 1000.245
--
===== CNT=1; DSN=1; C=100; N=1000; DATE=2013-07-27-14-31-36-980396;
Uptime: 63  Threads: 501  Questions: 62030  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 984.603
--
===== CNT=1; DSN=1; C=1000; N=10000; DATE=2013-07-27-14-31-38-493284;
Uptime: 78  Threads: 501  Questions: 72031  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 923.474
--
===== CNT=1; DSN=1; C=5000; N=50000; DATE=2013-07-27-14-31-53-18563;
Uptime: 129  Threads: 251  Questions: 122072  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 946.294

===== CNT=1; DSN=2; C=100; N=1000; DATE=2013-07-27-14-30-51-109835;
Complete requests:      1000
Requests per second:    3054.97 [#/sec] (mean)
--
===== CNT=1; DSN=2; C=1000; N=10000; DATE=2013-07-27-14-30-51-680217;
Complete requests:      10000
Requests per second:    2852.79 [#/sec] (mean)
--
===== CNT=1; DSN=2; C=5000; N=50000; DATE=2013-07-27-14-30-55-454527;
Complete requests:      50000
Requests per second:    1215.63 [#/sec] (mean)
--
===== CNT=1; DSN=1; C=100; N=1000; DATE=2013-07-27-14-31-36-980396;
Complete requests:      1000
Requests per second:    770.72 [#/sec] (mean)
--
===== CNT=1; DSN=1; C=1000; N=10000; DATE=2013-07-27-14-31-38-493284;
Complete requests:      10000
Requests per second:    692.58 [#/sec] (mean)
--
===== CNT=1; DSN=1; C=5000; N=50000; DATE=2013-07-27-14-31-53-18563;
Complete requests:      50000
Requests per second:    988.28 [#/sec] (mean)

間違い。phpで制限をかけるとpconnectを開放するのではなく、持続的接続が1つあるのでエラーになる。
Warning: mysql_pconnect(): Too many open links (1) in /var/www/localhost/htdocs/test/ab.php on line 30



pconnectの場合 DB::close の直前に SET wait_timeout=1; をやるのはあり。
多い時のDBへの接続が1秒辺りmax_connections以下かどうかとかで増やしたり減らしたり。
MySQL server has gone awayへの対処が必要。

2013-07-26

memo: eix-remote

http://www.gossamer-threads.com/lists/gentoo/user/251984

$ sudo eix-remote add
 * Unpacking data
/tmp/eix-remote.V9ZKHAyR/_var_lib_layman_Armageddon.eix was created with an incompatible eix-update:
It uses database format 32 (current is 31).
Please run 'eix-update' and try again.
problems occurred with cachefile _var_lib_layman_Armageddon.eix
...

アップデートする場合は/etc/eixrcの名前が変わることに注意する。
バージョン戻しても元には戻らない。
$ sudo ACCEPT_KEYWORDS="~*" emerge --oneshot -avt eix

These are the packages that would be merged, in reverse order:

Calculating dependencies... done!
[ebuild     U  ] app-portage/eix-0.29.1 [0.25.5] USE="dep nls -clang% -debug -doc -optimization -security -sqlite -strong-optimization -strong-security% -swap-remote% -tools -zsh-completion" LINGUAS="-de% -ru%" 0 kB
...
 * Messages for package app-portage/eix-0.29.1:

 *
 * Installation of a directory is blocked by a file:
 *   '/etc/eixrc'
 * This file will be renamed to a different name:
 *   '/etc/eixrc.backup.0000'
 *
...

$ find /etc/eixrc* -ls
1048706    4 drwxr-xr-x   2 root     root         4096  7月 26 00:04 /etc/eixrc
281462    4 -rw-r--r--   1 root     root         1232  7月 26 00:04 /etc/eixrc/00-eixrc
280672    4 -rw-r--r--   1 root     root         1304  7月 25 23:30 /etc/eixrc.backup.0000

$ sudo eix-update
$ sudo eix-remote add

$ eix --cache-file /var/cache/eix/portage.eix -* -c -C php | wc -l
250
$ eix --cache-file /var/cache/eix/remote.eix -* -c -C php | wc -l
317
$ eix --cache-file /var/cache/eix/portage.eix -* -c -C php -O | wc -l
0
$ eix --cache-file /var/cache/eix/remote.eix -* -c -C php -O | wc -l
84

$ man eix
...
       --cache-file FILE
              Use FILE instead of /var/cache/eix/portage.eix.
...

puttyの色付き文字が濃くなったように見える。
環境によるが今まで使っていない設定が使われているように見える。
$ eix --cache-file /var/cache/eix/remote.eix "^(paco|x?stow)$"
* app-admin/stow
     Available versions:  ~2.1.1 ~2.1.2 ~2.2.0 {test}
     Homepage:            http://www.gnu.org/software/stow/
     Description:         Manage installation of software in /var/lib/

* app-admin/xstow
     Available versions:  ~0.5.1 ~1.0.0 1.0.0-r1 {ncurses static}
     Homepage:            http://xstow.sourceforge.net/
     Description:         replacement for GNU stow with extensions

* app-admin/paco [1]
     Available versions:  2.0.9-r1 {gtk +tools}
     Homepage:            http://paco.sourceforge.net/
     Description:         Source code package organizer

[1] "foo-overlay" layman/foo-overlay

Found 3 matches.

2013-07-11

Load Tabs Progressively の代替

https://addons.mozilla.org/ja/firefox/addon/load-tabs-progressively/
https://addons.mozilla.org/ja/firefox/addon/bartab-lite/?src=search


複数のタブを保存したままfirefoxを起動した際に、保存されたタブのURLを読みこまないで、タブを選択した際にURLを読み込むアドオン。

BarTab
↓
Load Tabs Progressively
↓
BarTab Lite

Firefox 22.0 では利用できません、と表示されるので、違うアドオンを入れた。
元々BarTabの代替で入れたようだった。

TabMixPlusオプションの、Firefox内蔵のセッション復元機能を使用する、がOFFだと初回起動時のタブ読み込みでBarTabの機能がOFFになっている。
再起動ボタンのアドオンで再起動すると機能しているようなので気が付かないのかもしれない。