mib文件导入mysql数据库_mysql之 sysbench1.0.3 安装与系统压力测试

本文介绍了sysbench工具的下载、安装及使用,包括CPU性能测试、内存性能测试、磁盘IO性能测试和线程、互斥锁测试。sysbench是一个强大的系统和数据库压力测试工具,适用于评估和优化MySQL等数据库及系统性能。

针对系统和数据库压测是项目上线前必做的一项,这里使用的是最新版本的sysbench做的压测使用详解。sysbench可以做系统层面的压力测试(CPU、内存、硬盘IO、互斥锁、Thead),也可以做数据库(MySQL/Oracle/PG)层面的压力测试。安装容易,操作便捷,是压测使用的重要工具之一。

一、sysbench下载

项目地址:https://launchpad.net/sysbench下载地址:https://github.com/akopytov/sysbench/archive/1.0.3.tar.gz二、sysbench安装

[root@DB_TEST tools]# tar -xzvf sysbench-1.0.3.tar.gz

[root@DB_TEST tools]# cd sysbench-1.0.3

[root@DB_TEST sysbench-1.0.3]# ./autogen.sh

[root@DB_TEST sysbench-1.0.3]#./configure  --prefix=/usr/local/sysbench --with-mysql

[root@DB_TEST sysbench-1.0.3]# make

[root@DB_TEST sysbench-1.0.3]# make install

[root@DB_TEST sysbench-1.0.3]#  cp -rp /usr/local/sysbench/bin/sysbench  /usr/bin/

[root@DB_TEST sysbench-1.0.3]# /usr/local/sysbench/bin/sysbench --help

点击(此处)折叠或打开

[root@BJ-133-22 sysbench-1.0.3]# /usr/local/sysbench/bin/sysbench --help

Usage:

sysbench [options]... [testname] [command]

Commands implemented by most tests: prepare run cleanup help

General options:

--threads=N number of threads to use [1]

--events=N limit for total number of events [0]

--time=N limit for total execution time in seconds [10]

--forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off]

--thread-stack-size=SIZE size of stack per thread [64K]

--rate=N average transactions rate. 0 for unlimited rate [0]

--report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0]

--report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. []

--debug[=on|off] print more debugging info [off]

--validate[=on|off] perform validation checks where possible [off]

--help[=on|off] print help and exit [off]

--version[=on|off] print version and exit [off]

--config-file=FILENAME File containing command line options

--tx-rate=N deprecated alias for --rate [0]

--max-requests=N deprecated alias for --events [0]

--max-time=N deprecated alias for --time [0]

--num-threads=N deprecated alias for --threads [1]

Pseudo-Random Numbers Generator options:

--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]

--rand-spec-iter=N number of iterations used for numbers generation [12]

--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]

--rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]

--rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0]

--rand-pareto-h=N parameter h for pareto distibution [0.2]

Log options:

--verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]

--percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]

--histogram[=on|off] print latency histogram in report [off]

General database options:

--db-driver=STRING specifies database driver to use ('help' to get list of available drivers)

--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]

--db-debug[=on|off] print database-specific debug information [off]

Compiled-in database drivers:

mysql - MySQL driver

mysql options:

--mysql-host=[LIST,...] MySQL server host [localhost]

--mysql-port=[LIST,...] MySQL server port [3306]

--mysql-socket=[LIST,...] MySQL socket

--mysql-user=STRING MySQL user [sbtest]

--mysql-password=STRING MySQL password []

--mysql-db=STRING MySQL database name [sbtest]

--mysql-ssl[=on|off] use SSL connections, if available in the client library [off]

--mysql-ssl-cipher=STRING use specific cipher for SSL connections []

--mysql-compression[=on|off] use compression, if available in the client library [off]

--mysql-debug[=on|off] trace all client library calls [off]

--mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]

--mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]

Compiled-in tests:

fileio - File I/O test

cpu - CPU performance test

memory - Memory functions speed test

threads - Threads subsystem performance test

mutex - Mutex performance test

See 'sysbench help' for a list of options for each test.

三、sysbench使用

1、CPU性能测试

cpu性能测试:找范围内最大素数{时间越短越好}

cpu性能测试主要是根据素数的加法运算,这里指定最大素数(质数)为80000,--num-threads=`grep "processor" /proc/cpuinfo | wc -l`指定线程数,默认是1

/usr/local/sysbench/bin/sysbench --test=cpu --cpu-max-prime=80000 run

点击(此处)折叠或打开

[root@db_test ~]# /usr/local/sysbench/bin/sysbench --test=cpu --cpu-max-prime=80000 run

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 1

Initializing random number generator from current time

Prime numbers limit: 80000

Initializing worker threads...

Threads started!

General statistics:

total time: 10.0057s

total number of events: 520

Latency (ms):

min: 18.74

avg: 19.24

max: 19.39

95th percentile: 19.29

sum: 10005.32

Threads fairness:

events (avg/stddev): 520.0000/0.00

execution time (avg/stddev): 10.0053/0.00

实际环境CPU拷机压测脚本如下:

echo -e "进行CPU压力测试: 寻找小于1千万的最大质数,并发线程数10,最大请求数100 "

/usr/local/bin/sysbench --num-threads=10 --max-requests=100 --test=cpu --debug --cpu-max-prime=10000000 run

2、内存性能测试

sysbench 测试memory的时候是顺序读或写内存的。根据选项的不同,每次操作过程中,每个线程可以获取global或本地的数据块

内存:以不同块大小传输一定数量的数据吞吐量大小{越大越好}

点击(此处)折叠或打开

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench --test=memory help

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

memory options:

--memory-block-size=SIZE size of memory block for test [1K]  测试时内存块大小

--memory-total-size=SIZE total size of data to transfer [100G] 传输数据总大小

--memory-scope=STRING memory access scope {global,local} [global]  内存访问范围

--memory-hugetlb[=on|off] allocate memory from HugeTLB pool [off] 从 HugeTLB pool内存分配

--memory-oper=STRING type of memory operations {read, write, none} [write] 内存操作类型

--memory-access-mode=STRING memory access mode {seq,rnd} [seq] 存储器存取方式

示例:测试传输数据总量为5G,每个块大小是1K(一般设置是8K),连续读写的情况下,吞吐量3435.87 MiB/sec

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench --test=memory --memory-block-size=1K --memory-total-size=5G run

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 1

Initializing random number generator from current time

Initializing worker threads...

Threads started!

Operations performed: 5242880 (3518332.06 ops/sec)

5120.00 MiB transferred (3435.87 MiB/sec)

General statistics:

total time:                          1.4883s

total number of events:              5242880

Latency (ms):

min:                                  0.00

avg:                                  0.00

max:                                  0.03

95th percentile:                      0.00

sum:                                631.01

Threads fairness:

events (avg/stddev):           5242880.0000/0.00

execution time (avg/stddev):   0.6310/0.00

实际内存压力测试脚本:

echo -e "进行内存压力测试: 测试范围32G,并发线程数10,最大请求数100, 读 "

/usr/local/bin/sysbench --num-threads=10 --max-requests=100 --test=memory --memory-block-size=8K --memory-total-size=${MEM}G --memory-oper=read run

echo -e "进行内存压力测试: 测试范围32G,并发线程数10,最大请求数100, 写 "

/usr/local/bin/sysbench --num-threads=10 --max-requests=100 --test=memory --memory-block-size=8K --memory-total-size=${MEM}G --memory-oper=write run

3、磁盘IO性能测试

IO性能测试:不同场景下IOPS{越大越好}

点击(此处)折叠或打开

[root@db_test sysbench-1.0.3]# /usr/local/sysbench/bin/sysbench --test=fileio help

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

fileio options:

--file-num=N number of files to create [128]

--file-block-size=N block size to use in all IO operations [16384]

--file-total-size=SIZE total size of files to create [2G]

--file-test-mode=STRING test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}

--file-io-mode=STRING file operations mode {sync,async,mmap} [sync]

--file-async-backlog=N number of asynchronous operatons to queue per thread [128]

--file-extra-flags=STRING additional flags to use on opening files {sync,dsync,direct} []

--file-fsync-freq=N do fsync() after this number of requests (0 - don't use fsync()) [100]

--file-fsync-all[=on|off] do fsync() after each write operation [off]

--file-fsync-end[=on|off] do fsync() at the end of test [on]

--file-fsync-mode=STRING which method to use for synchronization {fsync, fdatasync} [fsync]

--file-merged-requests=N merge at most this number of IO requests if possible (0 - don't merge) [0]

--file-rw-ratio=N reads/writes ratio for combined test [1.5]

--file-num=N                       创建测试文件数量,默认是 [128]

--file-block-size=N                测试时文件块大小,默认是[16384],即16K

--file-total-size=SIZE             测试文件的总大小,默认是 [2G]

--file-test-mode=STRING            测试模式 {seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)}

--file-io-mode=STRING              文件操作模式{sync,async,mmap} [sync]

--file-extra-flags=STRING          使用额外的标志打开文件 {sync,dsync,direct} []

--file-fsync-freq=N                执行fsync()频率,0表示不使用,默认100

--file-fsync-all=[on|off]          每执行一次写操作执行一次fsync(),默认 [off]

--file-fsync-end=[on|off]          测试结束执行fsync(),默认 [on]

--file-fsync-mode=STRING           同步方法 {fsync, fdatasync} [fsync]

--file-merged-requests=N           如果可以,则合并IO请求数,默认0表示不合并

--file-rw-ratio=N                  测试读写比例,默认[1.5]

seqwr 顺序写入

seqrewr 顺序重写

seqrd 顺序读取

rndrd 随机读取

rndwr 随机写入

rndrw 混合随机读/写

FileIO示例01:prepare命令创建了128个文件总共大小为10G,文件读写模式为随机读写混合方式。run命令则进行测试,并返回结果,cleanup删除测试产生的文件!

##Fileio准备工作,生成测试数据(最好比内存的2倍大)

[root@db_test fileio]#/usr/local/sysbench/bin/sysbench  --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw prepare

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

WARNING: --num-threads is deprecated, use --threads instead

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

128 files, 81920Kb each, 10240Mb total

Creating files for the test...

Extra file open flags: 0

Creating file test_file.0

...

Creating file test_file.127

10737418240 bytes written in 9.96 seconds (1027.97 MiB/sec).

##正式执行FileIO测试

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench  --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw run

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

WARNING: --num-threads is deprecated, use --threads instead

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 16

Initializing random number generator from current time

Extra file open flags: 0

128 files, 80MiB each

10GiB total file size

Block size 16KiB

Number of IO requests: 0

Read/Write ratio for combined random IO test: 1.50

Periodic FSYNC enabled, calling fsync() each 100 requests.

Calling fsync() at the end of test, Enabled.

Using synchronous I/O mode

Doing random r/w test

Initializing worker threads...

Threads started!

File operations:

reads/s:                      1449.16

writes/s:                     965.91

fsyncs/s:                     3083.55

Throughput:

read, MiB/s:22.64

written, MiB/s:15.09

General statistics:

total time:                          10.4176s

total number of events:              57291

Latency (ms):

min:                                  0.00

avg:                                  2.87

max:                                825.08

95th percentile:                      0.17

sum:                             164312.66

Threads fairness:

events (avg/stddev):           3580.6875/469.53

execution time (avg/stddev):   10.2695/0.08

IO密切相关的包括每秒请求数和总吞吐量,其中请求数是(1449.16+965.91+3083.55)/s,吞吐量是(22.64+15.09)MB/s

##清理创建的文件

[root@db_test fileio]#/usr/local/sysbench/bin/sysbench  --num-threads=16 --test=fileio --file-total-size=10G --file-test-mode=rndrw cleanup

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

WARNING: --num-threads is deprecated, use --threads instead

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

Removing test files...

实际环境FILEIO压力测试脚本:

echo -e "进行IO压力测试: 20个文件,每个10GB,随机读写 "

/usr/local/bin/sysbench --file-num=20 --num-threads=20 --test=fileio --file-total-size=${HDD}G --max-requests=1000000 --file-test-mode=rndrw prepare

/usr/local/bin/sysbench --file-num=20 --num-threads=20 --test=fileio --file-total-size=${HDD}G --max-requests=1000000 --file-test-mode=rndrw run

/usr/local/bin/sysbench --file-num=20 --num-threads=20 --test=fileio --file-total-size=${HDD}G --max-requests=1000000 --file-test-mode=rndrw cleanup

4、thread测试

线程调度:线程并发执行,循环响应信号量花费的时间{越少越好}

测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用

点击(此处)折叠或打开

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench --test=threads help

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

threads options:

--thread-yields=N number of yields to do per request [1000] 每个请求产生多少个线程,默认[1000]

--thread-locks=N number of locks per thread [8]    每个线程的锁数量,默认 [8]

示例:

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench --num-threads=64 --test=threads --thread-yields=100 --thread-locks=2 run

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

WARNING: --num-threads is deprecated, use --threads instead

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 64

Initializing random number generator from current time

Initializing worker threads...

Threads started!

General statistics:

total time:                          10.0043s

total number of events:              102842

Latency (ms):

min:                                  0.02

avg:                                  6.22

max:                                 28.83

95th percentile:                     15.00

sum:                             640039.96

Threads fairness:

events (avg/stddev):           1606.9062/31.79

execution time (avg/stddev):   10.0006/0.00

5、互斥锁测试

互斥锁:并发线程同时申请互斥锁循环一定次数花费的时间{越少越好}

测试互斥锁的性能,方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁

点击(此处)折叠或打开

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench --test=mutex help

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

mutex options:

--mutex-num=N total size of mutex array [4096] 数组互斥总大小,默认[4096]

--mutex-locks=N number of mutex locks to do per thread [50000] 每个线程互斥锁的数量,默认 [50000]

--mutex-loops=N number of empty loops to do inside mutex lock [10000] 内部互斥锁的空循环数量,默认 [10000]

所有线程同时执行,获取短时间的mutex lock,以便测试mutex的实现!

示例:

[root@db_test fileio]# /usr/local/sysbench/bin/sysbench --test=mutex --mutex-num=4096 --mutex-locks=50000 --mutex-loops=20000 run

WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.

sysbench 1.0.3 (using bundled LuaJIT 2.1.0-beta2)

Running the test with following options:

Number of threads: 1

Initializing random number generator from current time

Initializing worker threads...

Threads started!

General statistics:

total time:                          0.0021s

total number of events:              1

Latency (ms):

min:                                  2.05

avg:                                  2.05

max:                                  2.05

95th percentile:                      2.03

sum:                                  2.05

Threads fairness:

events (avg/stddev):           1.0000/0.00

execution time (avg/stddev):   0.0020/0.00

内容概要:本文详细介绍了一个基于Java和Vue的联邦学习隐私保护推荐系统的设计实现。系统采用联邦学习架构,使用户数据在本地完成模型训练,仅上传加密后的模型参数或梯度,通过中心服务器进行联邦平均聚合,从而实现数据隐私保护协同建模的双重目标。项目涵盖完整的系统架构设计,包括本地模型训练、中心参数聚合、安全通信、前后端解耦、推荐算法插件化等模块,并结合差分隐私同态加密等技术强化安全性。同时,系统通过Vue前端实现用户行为采集个性化推荐展示,Java后端支撑高并发服务日志处理,形成“本地训练—参数上传—全局聚合—模型下发—个性化微调”的完整闭环。文中还提供了关键模块的代码示例,如特征提取、模型聚合、加密上传等,增强了项目的可实施性工程参考价值。 适合人群:具备一定Java和Vue开发基础,熟悉Spring Boot、RESTful API、分布式系统或机器学习相关技术,从事推荐系统、隐私计算或全栈开发方向的研发人员。 使用场景及目标:①学习联邦学习在推荐系统中的工程落地方法;②掌握隐私保护机制(如加密传输、差分隐私)模型聚合技术的集成;③构建高安全、可扩展的分布式推荐系统原型;④实现前后端协同的个性化推荐闭环系统。 阅读建议:建议结合代码示例深入理解联邦学习流程,重点关注本地训练全局聚合的协同逻辑,同时可基于项目架构进行算法替换功能扩展,适用于科研验证工业级系统原型开发。
源码来自:https://pan.quark.cn/s/a4b39357ea24 遗传算法 - 简书 遗传算法的理论是根据达尔文进化论而设计出来的算法: 人类是朝着好的方向(最优解)进化,进化过程中,会自动选择优良基因,淘汰劣等基因。 遗传算法(英语:genetic algorithm (GA) )是计算数学中用于解决最佳化的搜索算法,是进化算法的一种。 进化算法最初是借鉴了进化生物学中的一些现象而发展起来的,这些现象包括遗传、突变、自然选择、杂交等。 搜索算法的共同特征为: 首先组成一组候选解 依据某些适应性条件测算这些候选解的适应度 根据适应度保留某些候选解,放弃其他候选解 对保留的候选解进行某些操作,生成新的候选解 遗传算法流程 遗传算法的一般步骤 my_fitness函数 评估每条染色体所对应个体的适应度 升序排列适应度评估值,选出 前 parent_number 个 个体作为 待选 parent 种群(适应度函数的值越小越好) 从 待选 parent 种群 中随机选择 2 个个体作为父方和母方。 抽取父母双方的染色体,进行交叉,产生 2 个子代。 (交叉概率) 对子代(parent + 生成的 child)的染色体进行变异。 (变异概率) 重复3,4,5步骤,直到新种群(parentnumber + childnumber)的产生。 循环以上步骤直至找到满意的解。 名词解释 交叉概率:两个个体进行交配的概率。 例如,交配概率为0.8,则80%的“夫妻”会生育后代。 变异概率:所有的基因中发生变异的占总体的比例。 GA函数 适应度函数 适应度函数由解决的问题决定。 举一个平方和的例子。 简单的平方和问题 求函数的最小值,其中每个变量的取值区间都是 [-1, ...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值