From abff7ab5ae8268520c7fc069a895748910babab9 Mon Sep 17 00:00:00 2001 From: yanfeizhang Date: Sun, 8 May 2022 15:40:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E7=A3=81=E7=9B=98?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E5=AE=9E=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + tests/disk/test01/randread.fio | 91 +++++++++++++++++++++++++++++++ tests/disk/test01/randread.php | 64 ++++++++++++++++++++++ tests/disk/test01/randwrite.fio | 95 +++++++++++++++++++++++++++++++++ tests/disk/test01/randwrite.php | 64 ++++++++++++++++++++++ tests/disk/test01/read.fio | 91 +++++++++++++++++++++++++++++++ tests/disk/test01/read.php | 64 ++++++++++++++++++++++ tests/disk/test01/write.fio | 95 +++++++++++++++++++++++++++++++++ tests/disk/test01/write.php | 64 ++++++++++++++++++++++ tests/index.md | 17 ++++++ 10 files changed, 647 insertions(+) create mode 100644 .gitignore create mode 100755 tests/disk/test01/randread.fio create mode 100755 tests/disk/test01/randread.php create mode 100755 tests/disk/test01/randwrite.fio create mode 100755 tests/disk/test01/randwrite.php create mode 100755 tests/disk/test01/read.fio create mode 100755 tests/disk/test01/read.php create mode 100755 tests/disk/test01/write.fio create mode 100755 tests/disk/test01/write.php create mode 100644 tests/index.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c1f854e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +*.zip diff --git a/tests/disk/test01/randread.fio b/tests/disk/test01/randread.fio new file mode 100755 index 0000000..2e47dea --- /dev/null +++ b/tests/disk/test01/randread.fio @@ -0,0 +1,91 @@ +[global] +ioengine=libaio +direct=1 +filename=/search/odin/test.log +size=100G +ioscheduler=noop +refill_buffers +unified_rw_reporting=0 +time_based +runtime=300 + +[test-randrandread-512] +ioengine=libaio +rw=randread +bs=512b + +[test-randread-1k] +ioengine=libaio +rw=randread +bs=1k + +[test-randread-2k] +ioengine=libaio +rw=randread +bs=2k + +[test-randread-4k] +ioengine=libaio +rw=randread +bs=4k + +[test-randread-8k] +ioengine=libaio +rw=randread +bs=8k + +[test-randread-16k] +ioengine=libaio +rw=randread +bs=16k + +[test-randread-32k] +ioengine=libaio +rw=randread +bs=32k + +[test-randread-64k] +ioengine=libaio +rw=randread +bs=64k + +[test-randread-128k] +ioengine=libaio +rw=randread +bs=128k + +[test-randread-256k] +ioengine=libaio +rw=randread +bs=256k + +[test-randread-1m] +ioengine=libaio +rw=randread +bs=1m + +[test-randread-2m] +ioengine=libaio +rw=randread +bs=2m + +[test-randread-4m] +ioengine=libaio +rw=randread +bs=4m + +[test-randread-8m] +ioengine=libaio +rw=randread +bs=8m + +[test-randread-16m] +ioengine=libaio +rw=randread +bs=16m + +[test-randread-32m] +ioengine=libaio +rw=randread +bs=32m + diff --git a/tests/disk/test01/randread.php b/tests/disk/test01/randread.php new file mode 100755 index 0000000..74986ae --- /dev/null +++ b/tests/disk/test01/randread.php @@ -0,0 +1,64 @@ +_out, ""); + + $sections = $this->getSections($this->_in); + foreach($sections as $sec){ + $fioResult = $this->runFioTest($sec); + file_put_contents("data/".$sec, $fioResult); + $res = $this->parseFioResult($fioResult); + + $line = $sec."\t".$res['bw']."\t".$res['lat']."\t".$res['iops']."\n"; + echo $line; + file_put_contents($this->_out, $line, FILE_APPEND); + sleep(60); + } + } + + public function parseFioResult($fioResult){ + $result = array(); + $fio = json_decode($fioResult, true); + $result['iops'] = $fio["jobs"][0]['read']['iops_mean']; + $result['bw'] = $fio["jobs"][0]['read']['bw_mean']; //kb + $result['lat'] = $fio["jobs"][0]['read']["lat_ns"]['mean']; //ns + return $result; + } + + public function runFioTest($section){ + $cmd = "fio ".$this->_in." --section=".$section." --output-format=json"; + echo $cmd."\n"; + $result = shell_exec($cmd); + return $result; + } + + public function getSections($fioFile){ + $matches = array(); + $contents = file_get_contents($fioFile); + $pattern = '/\[(.+)\]/'; + preg_match_all($pattern, $contents, $matches); + + $secs = array(); + foreach($matches[1] as $sec){ + if($sec=="global"){ + continue; + } + $secs[] = $sec; + } + return $secs; + } +} + +$test = new FioTest(); +$test->run(); + + + + + + + diff --git a/tests/disk/test01/randwrite.fio b/tests/disk/test01/randwrite.fio new file mode 100755 index 0000000..83120f7 --- /dev/null +++ b/tests/disk/test01/randwrite.fio @@ -0,0 +1,95 @@ +[global] +ioengine=libaio +direct=1 +filename=/search/odin/test.log +size=100G +ioscheduler=noop +refill_buffers +unified_rw_reporting=0 +time_based +runtime=300 + +[test-randwrite-512] +ioengine=libaio +rw=randwrite +bs=512b + +[test-randwrite-1k] +ioengine=libaio +rw=randwrite +bs=1k + +[test-randwrite-2k] +ioengine=libaio +rw=randwrite +bs=2k + +[test-randwrite-4k] +ioengine=libaio +rw=randwrite +bs=4k + +[test-randwrite-8k] +ioengine=libaio +rw=randwrite +bs=8k + +[test-randwrite-16k] +ioengine=libaio +rw=randwrite +bs=16k + +[test-randwrite-32k] +ioengine=libaio +rw=randwrite +bs=32k + +[test-randwrite-64k] +ioengine=libaio +rw=randwrite +bs=64k + +[test-randwrite-128k] +ioengine=libaio +rw=randwrite +bs=128k + +[test-randwrite-256k] +ioengine=libaio +rw=randwrite +bs=256k + +[test-randwrite-512k] +ioengine=libaio +rw=randwrite +bs=512k + +[test-randwrite-1m] +ioengine=libaio +rw=randwrite +bs=1m + +[test-randwrite-2m] +ioengine=libaio +rw=randwrite +bs=2m + +[test-randwrite-4m] +ioengine=libaio +rw=randwrite +bs=4m + +[test-randwrite-8m] +ioengine=libaio +rw=randwrite +bs=8m + +[test-randwrite-16m] +ioengine=libaio +rw=randwrite +bs=16m + +[test-randwrite-32m] +ioengine=libaio +rw=randwrite +bs=32m diff --git a/tests/disk/test01/randwrite.php b/tests/disk/test01/randwrite.php new file mode 100755 index 0000000..67a0aeb --- /dev/null +++ b/tests/disk/test01/randwrite.php @@ -0,0 +1,64 @@ +_out, ""); + + $sections = $this->getSections($this->_in); + foreach($sections as $sec){ + $fioResult = $this->runFioTest($sec); + file_put_contents("data/".$sec, $fioResult); + $res = $this->parseFioResult($fioResult); + + $line = $sec."\t".$res['bw']."\t".$res['lat']."\t".$res['iops']."\n"; + echo $line; + file_put_contents($this->_out, $line, FILE_APPEND); + sleep(60); + } + } + + public function parseFioResult($fioResult){ + $result = array(); + $fio = json_decode($fioResult, true); + $result['iops'] = $fio["jobs"][0]['write']['iops_mean']; + $result['bw'] = $fio["jobs"][0]['write']['bw_mean']; //kb + $result['lat'] = $fio["jobs"][0]['write']["lat_ns"]['mean']; //ns + return $result; + } + + public function runFioTest($section){ + $cmd = "fio ".$this->_in." --section=".$section." --output-format=json"; + echo $cmd."\n"; + $result = shell_exec($cmd); + return $result; + } + + public function getSections($fioFile){ + $matches = array(); + $contents = file_get_contents($fioFile); + $pattern = '/\[(.+)\]/'; + preg_match_all($pattern, $contents, $matches); + + $secs = array(); + foreach($matches[1] as $sec){ + if($sec=="global"){ + continue; + } + $secs[] = $sec; + } + return $secs; + } +} + +$test = new FioTest(); +$test->run(); + + + + + + + diff --git a/tests/disk/test01/read.fio b/tests/disk/test01/read.fio new file mode 100755 index 0000000..e0fa4ea --- /dev/null +++ b/tests/disk/test01/read.fio @@ -0,0 +1,91 @@ +[global] +ioengine=libaio +direct=1 +filename=/search/odin/test.log +size=100G +ioscheduler=noop +refill_buffers +unified_rw_reporting=0 +time_based +runtime=300 + +[test-read-512] +ioengine=libaio +rw=read +bs=512b + +[test-read-1k] +ioengine=libaio +rw=read +bs=1k + +[test-read-2k] +ioengine=libaio +rw=read +bs=2k + +[test-read-4k] +ioengine=libaio +rw=read +bs=4k + +[test-read-8k] +ioengine=libaio +rw=read +bs=8k + +[test-read-16k] +ioengine=libaio +rw=read +bs=16k + +[test-read-32k] +ioengine=libaio +rw=read +bs=32k + +[test-read-64k] +ioengine=libaio +rw=read +bs=64k + +[test-read-128k] +ioengine=libaio +rw=read +bs=128k + +[test-read-256k] +ioengine=libaio +rw=read +bs=256k + +[test-read-1m] +ioengine=libaio +rw=read +bs=1m + +[test-read-2m] +ioengine=libaio +rw=read +bs=2m + +[test-read-4m] +ioengine=libaio +rw=read +bs=4m + +[test-read-8m] +ioengine=libaio +rw=read +bs=8m + +[test-read-16m] +ioengine=libaio +rw=read +bs=16m + +[test-read-32m] +ioengine=libaio +rw=read +bs=32m + diff --git a/tests/disk/test01/read.php b/tests/disk/test01/read.php new file mode 100755 index 0000000..b6e605b --- /dev/null +++ b/tests/disk/test01/read.php @@ -0,0 +1,64 @@ +_out, ""); + + $sections = $this->getSections($this->_in); + foreach($sections as $sec){ + $fioResult = $this->runFioTest($sec); + file_put_contents("data/".$sec, $fioResult); + $res = $this->parseFioResult($fioResult); + + $line = $sec."\t".$res['bw']."\t".$res['lat']."\t".$res['iops']."\n"; + echo $line; + file_put_contents($this->_out, $line, FILE_APPEND); + sleep(60); + } + } + + public function parseFioResult($fioResult){ + $result = array(); + $fio = json_decode($fioResult, true); + $result['iops'] = $fio["jobs"][0]['read']['iops_mean']; + $result['bw'] = $fio["jobs"][0]['read']['bw_mean']; //kb + $result['lat'] = $fio["jobs"][0]['read']["lat_ns"]['mean']; //ns + return $result; + } + + public function runFioTest($section){ + $cmd = "fio ".$this->_in." --section=".$section." --output-format=json"; + echo $cmd."\n"; + $result = shell_exec($cmd); + return $result; + } + + public function getSections($fioFile){ + $matches = array(); + $contents = file_get_contents($fioFile); + $pattern = '/\[(.+)\]/'; + preg_match_all($pattern, $contents, $matches); + + $secs = array(); + foreach($matches[1] as $sec){ + if($sec=="global"){ + continue; + } + $secs[] = $sec; + } + return $secs; + } +} + +$test = new FioTest(); +$test->run(); + + + + + + + diff --git a/tests/disk/test01/write.fio b/tests/disk/test01/write.fio new file mode 100755 index 0000000..70ddfe6 --- /dev/null +++ b/tests/disk/test01/write.fio @@ -0,0 +1,95 @@ +[global] +ioengine=libaio +direct=1 +filename=/search/odin/test.log +size=100G +ioscheduler=noop +refill_buffers +unified_rw_reporting=0 +time_based +runtime=300 + +[test-write-512] +ioengine=libaio +rw=write +bs=512b + +[test-write-1k] +ioengine=libaio +rw=write +bs=1k + +[test-write-2k] +ioengine=libaio +rw=write +bs=2k + +[test-write-4k] +ioengine=libaio +rw=write +bs=4k + +[test-write-8k] +ioengine=libaio +rw=write +bs=8k + +[test-write-16k] +ioengine=libaio +rw=write +bs=16k + +[test-write-32k] +ioengine=libaio +rw=write +bs=32k + +[test-write-64k] +ioengine=libaio +rw=write +bs=64k + +[test-write-128k] +ioengine=libaio +rw=write +bs=128k + +[test-write-256k] +ioengine=libaio +rw=write +bs=256k + +[test-write-512k] +ioengine=libaio +rw=write +bs=512k + +[test-write-1m] +ioengine=libaio +rw=write +bs=1m + +[test-write-2m] +ioengine=libaio +rw=write +bs=2m + +[test-write-4m] +ioengine=libaio +rw=write +bs=4m + +[test-write-8m] +ioengine=libaio +rw=write +bs=8m + +[test-write-16m] +ioengine=libaio +rw=write +bs=16m + +[test-write-32m] +ioengine=libaio +rw=write +bs=32m diff --git a/tests/disk/test01/write.php b/tests/disk/test01/write.php new file mode 100755 index 0000000..02be604 --- /dev/null +++ b/tests/disk/test01/write.php @@ -0,0 +1,64 @@ +_out, ""); + + $sections = $this->getSections($this->_in); + foreach($sections as $sec){ + $fioResult = $this->runFioTest($sec); + file_put_contents("data/".$sec, $fioResult); + $res = $this->parseFioResult($fioResult); + + $line = $sec."\t".$res['bw']."\t".$res['lat']."\t".$res['iops']."\n"; + echo $line; + file_put_contents($this->_out, $line, FILE_APPEND); + sleep(60); + } + } + + public function parseFioResult($fioResult){ + $result = array(); + $fio = json_decode($fioResult, true); + $result['iops'] = $fio["jobs"][0]['write']['iops_mean']; + $result['bw'] = $fio["jobs"][0]['write']['bw_mean']; //kb + $result['lat'] = $fio["jobs"][0]['write']["lat_ns"]['mean']; //ns + return $result; + } + + public function runFioTest($section){ + $cmd = "fio ".$this->_in." --section=".$section." --output-format=json"; + echo $cmd."\n"; + $result = shell_exec($cmd); + return $result; + } + + public function getSections($fioFile){ + $matches = array(); + $contents = file_get_contents($fioFile); + $pattern = '/\[(.+)\]/'; + preg_match_all($pattern, $contents, $matches); + + $secs = array(); + foreach($matches[1] as $sec){ + if($sec=="global"){ + continue; + } + $secs[] = $sec; + } + return $secs; + } +} + +$test = new FioTest(); +$test->run(); + + + + + + + diff --git a/tests/index.md b/tests/index.md new file mode 100644 index 0000000..16be659 --- /dev/null +++ b/tests/index.md @@ -0,0 +1,17 @@ + +## CPU相关实验 +- [likely 和 unlikely 汇编结果对比](tests/cpu/test01) + +## 磁盘相关实验 +- [使用fio磁盘压测工具进行性能压测分析](tests/disk/test01) + +## 网络相关实验 +- [PHP单语言的百万连接测试源码](tests/network/test01) +- [通过多 IP 达成单机百万连接(支持c、java、php三种语言)](tests/network/test02) +- [通过端口重用达成单机百万连接(支持c、java、php三种语言)](tests/network/test03) +- [一个模拟 tcpdump 的简单抓包程序](tests/network/test04) +- [用 bridge 连接本机上的多组 veth,使其可以互相通信](tests/network/test05) +- [命令行使用 namespace 的简单实验](tests/network/test06) +- [手工模拟实现一个可以和外部通信的容器网络](tests/network/test07) +- [socket端口复用SO_REUSEPORT测试](tests/network/test08) +