本文共 5857 字,大约阅读时间需要 19 分钟。
基准测试是一种测量和评估软件性能指标的活动。其主要目的是为系统在特定时间点建立性能基准。通过基准测试,我们可以了解系统在当前状态下的性能表现,并在系统发生硬件或软件更换时,重新进行测试以评估变化对性能的影响。
基准测试:直接且简单,易于比较,用于评估服务器的处理能力。
压力测试:
apt -y install make automake libtool pkg-config libaio-dev vim-common# 如果需要MySQL支持apt -y install libmysqlclient-dev# 如果需要PostgreSQL支持apt -y install libpq-dev
unzip 0.5.zipcd sysbench-0.5./autogen.sh# 添加支持PostgreSQL./configuremakemake install
create database sysbenchtest;
grant all privileges on sysbenchtest.* to sysbench@'localhost' identified by '4rfv$RFV';flush privileges;
sysbench --test=./sysbench/tests/db/oltp.lua \--mysql-host=127.0.0.1 \--mysql-db=sysbenchtest \--mysql-user=sysbench \--mysql-password='4rfv$RFV' \--oltp-test-mode=complex \--oltp-tables-count=5 \--oltp-table-size=100000 \--threads=10 \--time=120 \--rand-init=on \--report-interval=10 \--mysql-table-engine=innodb \prepare
--oltp-tables-count=5:生成5张表--oltp-table-size=100000:每张表包含100000条记录--oltp-test-mode=complex:使用复杂的事务模式--rand-init=on:随机初始化数据--report-interval=10:每10秒输出一次测试进度报告sysbench --test=./sysbench/tests/db/oltp.lua \--mysql-table-engine=innodb \--mysql-host=127.0.0.1 \--mysql-db=sysbenchtest \--mysql-user=sysbench \--mysql-password='4rfv$RFV' \--num-threads=8 \--oltp-table-size=100000 \--oltp_tables_count=5 \--oltp-read-only=off \--report-interval=10 \--rand-type=uniform \--max-time=30 \--max-requests=0 \--percentile=99 \run > ./log/sysbench.log
sysbench --test=./sysbench/tests/db/oltp.lua \--mysql-table-engine=innodb \--mysql-host=127.0.0.1 \--mysql-db=sysbenchtest \--num-threads=8 \--oltp-table-size=100000 \--oltp_tables_count=5 \--oltp-read-only=off \--report-interval=10 \--rand-type=uniform \--max-time=600 \--max-requests=0 \--mysql-user=test \--mysql-password='4rfv$RFV' \cleanup
#!/usr/bin/env pythonimport reimport oslogFile = open('/root/sysbench-0.5/log/sysbench.log', 'r')analysisFile = open('/root/sysbench-0.5/log/analysis.log', 'a+')def closeFile(file): file.close()def analysis(): print("开始分析...") transactions = [] readWrite = [] minTime = [] avgTime = [] maxTime = [] approxTime = [] for line in logFile: match = re.search(r'transactions:\s*(\d+\.\d*).*', line) if match: transactions.append(float(match.group(1))) match = re.search(r'read/write requests:\s*(\d+\.\d*).*', line) if match: readWrite.append(float(match.group(1))) match = re.search(r'min:\s*(\d+\.?\d*).*', line) if match: minTime.append(float(match.group(1))) match = re.search(r'avg:\s*(\d+\.?\d*).*', line) if match: avgTime.append(float(match.group(1))) match = re.search(r'max:\s*(\d+\.?\d*).*', line) if match: maxTime.append(float(match.group(1))) match = re.search(r'approx.*?(\d+\.\d*).*', line) if match: approxTime.append(float(match.group(1))) if not transactions: return sum_transactions = sum(transactions) avg_transaction = sum_transactions / len(transactions) analysisFile.write("每秒事务数:%.2f\n" % avg_transaction) if not readWrite: return sum_readWrite = sum(readWrite) avg_readWrite = sum_readWrite / len(readWrite) analysisFile.write("每秒读写数:%.2f\n" % avg_readWrite) if not minTime: return sum_minTime = sum(minTime) avg_minTime = sum_minTime / len(minTime) analysisFile.write("最小响应时间:%.2fms\n" % avg_minTime) if not maxTime: return sum_maxTime = sum(maxTime) avg_maxTime = sum_maxTime / len(maxTime) analysisFile.write("最大响应时间:%.2fms\n" % avg_maxTime) if not avgTime: return sum_avgTime = sum(avgTime) avg_avgTime = sum_avgTime / len(avgTime) analysisFile.write("平均响应时间:%.2fms\n" % avg_avgTime) analysisFile.write("=" * 20 + "\n") print("分析完成...") closeFile(analysisFile)def prepare(): print("准备数据...") os.system("sysbench --test=/root/sysbench-0.5/sysbench/tests/db/oltp.lua \ --mysql-host=127.0.0.1 \ --mysql-db=sysbenchtest \ --mysql-user=sysbench \ --mysql-password='4rfv$RFV' \ --oltp-test-mode=complex \ --oltp-tables-count=5 \ --oltp-table-size=100000 \ --threads=10 \ --time=120 \ --rand-init=on \ --report-interval=10 \ --mysql-table-engine=innodb \ prepare")def experiment(): print("执行测试...") os.system("sysbench --test=/root/sysbench-0.5/sysbench/tests/db/oltp.lua \ --mysql-table-engine=innodb \ --mysql-host=127.0.0.1 \ --mysql-db=sysbenchtest \ --mysql-user=sysbench \ --mysql-password='4rfv$RFV' \ --num-threads=8 \ --oltp-table-size=100000 \ --oltp_tables_count=5 \ --oltp-read-only=off \ --report-interval=10 \ --rand-type=uniform \ --max-time=30 \ --max-requests=0 \ --percentile=99 \ run > /root/sysbench-0.5/log/sysbench.log")def clean(): print("清空测试数据...") os.system("sysbench --test=/root/sysbench-0.5/sysbench/tests/db/oltp.lua \ --mysql-table-engine=innodb \ --mysql-host=127.0.0.1 \ --mysql-db=sysbenchtest \ --num-threads=8 \ --oltp-table-size=100000 \ --oltp_tables_count=5 \ --oltp-read-only=off \ --report-interval=10 \ --rand-type=uniform \ --max-time=600 \ --max-requests=0 \ --mysql-user=test \ --mysql-password='4rfv$RFV' \ cleanup")if __name__ == '__main__': for i in range(3): prepare() experiment() clean() analysis() 感谢每一位认真阅读我的文章的朋友。虽然这并不是什么值钱的东西,但如果我的内容对你有帮助,随时可以直接使用。如果你需要更多关于软件测试的资源,可以点击下方卡片获取。
转载地址:http://xfdfk.baihongyu.com/