自学内容网 自学内容网

sysbench进行pg测试

sysbench测试

官方地址:

https://github.com/akopytov/sysbench

简介

sysbench 是一款基于 LuaJIT 的可编写脚本的多线程基准测试工具。它最常用于数据库基准测试。

Sysbench 支持多种测试类型,主要包括:

  1. CPU性能测试:通过质数计算或圆周率计算来评估CPU性能。
  2. 内存性能测试:测试系统的内存分配及传输速度。
  3. 磁盘IO性能测试:测试系统的磁盘读写速度。
  4. 调度程序性能测试:评估操作系统的调度程序性能。
  5. POSIX线程性能测试:评估系统的线程处理能力。
  6. 数据库性能测试(OLTP基准测试):通过模拟数据库操作来评估数据库性能,支持 MySQL、Oracle、PostgreSQL 等数据库。

源码安装

因为要测试postgresql,所以使用了--with-pgsql

tar zxvf sysbench-1.0.20.tar.gz
./autogen.sh
./configure --without-mysql --with-pgsql
make
make install

如果报错:

checking for pg_config... no
configure: error: pg_config executable not found
********************************************************************************
ERROR: cannot find PostgreSQL libraries. If you want to compile with PosgregSQL support,
       you must either specify file locations explicitly using
       --with-pgsql-includes and --with-pgsql-libs options, or make sure path to
       pg_config is listed in your PATH environment variable. If you want to
       disable PostgreSQL support, use --without-pgsql option.
********************************************************************************

碰到这个错误需要设置pg的lib目录

export PATH=/data/postgres/12.5/bin:$PATH

输出:

===============================================================================
sysbench version   : 1.0.20
CC                 : gcc -std=gnu99
CFLAGS             : -O2 -funroll-loops  -Wall -Wextra -Wpointer-arith -Wbad-function-cast -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wcast-align -Wvla   -pthread
CPPFLAGS           : -D_GNU_SOURCE   -I$(top_srcdir)/src -I$(abs_top_builddir)/third_party/luajit/inc -I$(abs_top_builddir)/third_party/concurrency_kit/include
LDFLAGS            : -L/usr/local/lib 
LIBS               : -lm 
EXTRA_LDFLAGS      : 

prefix             : /usr/local
bindir             : ${prefix}/bin
libexecdir         : ${prefix}/libexec
mandir             : ${prefix}/share/man
datadir            : ${prefix}/share

MySQL support      : no
Drizzle support    : no
AttachSQL support  : no
Oracle support     : no
PostgreSQL support : yes

LuaJIT             : bundled
LUAJIT_CFLAGS      : -I$(abs_top_builddir)/third_party/luajit/inc
LUAJIT_LIBS        : $(abs_top_builddir)/third_party/luajit/lib/libluajit-5.1.a -ldl
LUAJIT_LDFLAGS     : -rdynamic

Concurrency Kit    : bundled
CK_CFLAGS          : -I$(abs_top_builddir)/third_party/concurrency_kit/include
CK_LIBS            : $(abs_top_builddir)/third_party/concurrency_kit/lib/libck.a
configure flags    : 
===============================================================================

使用

创建测试表并插入数据:

sysbench --db-driver=pgsql --pgsql-host=127.0.0.1 --pgsql-port=5432 --pgsql-user=postgres --pgsql-db=testdb --table_size=10000000 --tables=1 --threads=4 oltp_read_write prepare

--threads=4:指定并发执行测试的线程数为 4。

oltp_read_write prepare:这是 sysbench 的测试脚本和动作。oltp_read_write 是一个用于模拟 OLTP 场景(包括读写操作)的测试脚本。prepare 是这个脚本的一个阶段,用于准备测试环境,即创建测试表并填充数据。


原文地址:https://blog.csdn.net/shulu/article/details/142379490

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!