AntDB-单机oracle兼容版本TPCC性能分析(一)

背景


AntDB-单机oracle语法兼容版本,高并发下benchmarksql走oracle语法下性能较走pg本身语法下降40%左右。为了诊断软件的性能瓶颈,使用gprof工具在预编译AntDB时打开 –enable-profiling,这个选项会打开gcc的-pg参数,产生可以被gprof用于分析进程的代码。操作数据库后生成的诊断代码默认存放在$PGDATA/gprof目录中,每个进程结束后,都会产生一个子目录,里面会有一个gmon.out文件。

gprof工具简单介绍


gprof是GNU profile工具,可以运行于linux操作系统进行C、C++程序的性能分析,用于程序的性能优化以及程序瓶颈问题的查找和解决。通过分析应用程序运行时产生的“flat profile”,可以得到每个函数的调用次数,每个函数消耗的处理器时间,也可以得到函数的“Call graph 调用关系图”,包括函数调用的层次关系,每个函数调用花费了多少时间。

测试验证


step 1:使用–enable-profiling开关编译AntDB oracle 兼容版本


../adb_sql/configure --prefix=/data/gd/app --with-wal-segsize=64 --with-wal-blocksize=64
 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt --enable-thread-safety 
 --enable-cassert --enable-debug --enable-depend --disable-cluster --enable-grammar-oracle --enable-profiling CFLAGS=-O0 -ggdb3  
 && gmake install-world-contrib-recurse

备注: 1、–enable-profiling 是打开gprof开关,–disable-cluster –enable-grammar-oracle开关表示编译安装的是单机oracle语法兼容版本;
2、编译安装成功后,设置环境变量

step 2:初始化/配置/启动AntDB单机oracle兼容版本


[gd@intel175 ~]$ initdb -D data_oracle
The files belonging to this database system will be owned by user "gd".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory data_ora ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D data_oracle -l logfile start

设置参数后(postgresql.conf),顺带设置下pg_hba.conf 权限后启动AntDB oracle兼容版本,这里就不再细说。

setp3:初始化benchmarksql测试环境


[zgy@intel176 run]$ less runDatabaseBuild.sh 
#!/bin/sh

if [ $# -lt 1 ] ; then
    echo "usage: $(basename $0) PROPS [OPT VAL [...]]" >&2
    exit 2
fi

PROPS="$1"
shift
if [ ! -f "${PROPS}" ] ; then
    echo "${PROPS}: no such file or directory" >&2
    exit 1
fi
DB="$(grep '^db=' $PROPS | sed -e 's/^db=//')"

BEFORE_LOAD="tableCreates"
AFTER_LOAD="tableCopies indexCreates foreignKeys extraHistID buildFinish"

for step in ${BEFORE_LOAD} ; do
    ./runSQL.sh "${PROPS}" $step
done

#./runLoader.sh "${PROPS}" $*

for step in ${AFTER_LOAD} ; do
    ./runSQL.sh "${PROPS}" $step
done

benchmarksql 配置文件,本次验证通过gprof对单个进程的性能进行分析,选取100个数据仓库,1个并发,执行2分钟,如何初始化benchmarksql测试环境可以参考《benchmarksql测试AntDB》步骤,不再详细描述:

step 4:开启benchmarksql分别测试pg语法和oracle语法


100个数据仓库,1个并发,pg语法:

[zgy@intel176 run]$ vim props.pg_ora 
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://localhost:25432/postgres?binaryTransfer=false&forcebinary=false
user=benchmarksql
password=123456

warehouses=100
loadWorkers=4

terminals=1
//To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0
/:10
/To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=2
//Number of total transactions per minute
limitTxnsPerMin=0
测试结果:
11:34:28,386 [Thread-1] INFO   jTPCC : Term-00, Measured tpmC (NewOrders) = 506.77
11:34:28,386 [Thread-1] INFO   jTPCC : Term-00, Measured tpmTOTAL = 1131.0
11:34:28,386 [Thread-1] INFO   jTPCC : Term-00, Session Start     = 2018-08-08 11:32:28
11:34:28,386 [Thread-1] INFO   jTPCC : Term-00, Session End       = 2018-08-08 11:34:28
11:34:28,387 [Thread-1] INFO   jTPCC : Term-00, Transaction Count = 2262
11:34:28,387 [Thread-1] INFO   jTPCC : Term-00, New OrderTransaction Count = 1014
11:34:28,387 [Thread-1] INFO   jTPCC : Term-00, Transaction that execution successfully Count = 2255
11:34:28,387 [Thread-1] INFO   jTPCC : Term-00, Transaction that execution fails as expected Count = 7
11:34:28,387 [Thread-1] INFO   jTPCC : Term-00, Transaction that execution error Count = 0

100个数据仓库,1个并发,oracle 语法:

[zgy@intel176 run]$ vim props.pg_ora 
db=postgres
driver=org.postgresql.Driver
conn=jdbc:postgresql://localhost:25432/postgres?binaryTransfer=false&forcebinary=false
user=benchmarksql
password=123456

warehouses=100
loadWorkers=4

terminals=1
//To run specified transactions per terminal- runMins must equal zero
runTxnsPerTerminal=0
/:10
/To run for specified minutes- runTxnsPerTerminal must equal zero
runMins=2
//Number of total transactions per minute
limitTxnsPerMin=0
测试结果:
11:27:08,188 [Thread-1] INFO   jTPCC : Term-00, Measured tpmC (NewOrders) = 525.25
11:27:08,188 [Thread-1] INFO   jTPCC : Term-00, Measured tpmTOTAL = 1152.46
11:27:08,189 [Thread-1] INFO   jTPCC : Term-00, Session Start     = 2018-08-08 11:25:08
11:27:08,189 [Thread-1] INFO   jTPCC : Term-00, Session End       = 2018-08-08 11:27:08
11:27:08,189 [Thread-1] INFO   jTPCC : Term-00, Transaction Count = 2305
11:27:08,190 [Thread-1] INFO   jTPCC : Term-00, New OrderTransaction Count = 1051
11:27:08,190 [Thread-1] INFO   jTPCC : Term-00, Transaction that execution successfully Count = 2293
11:27:08,190 [Thread-1] INFO   jTPCC : Term-00, Transaction that execution fails as expected Count = 12
11:27:08,190 [Thread-1] INFO   jTPCC : Term-00, Transaction that execution error Count = 0

备注:记下每次执行时候,单进程的进程号,gprof生成的诊断代码默认存放在$PGDATA/gprof目录中,每个进程结束后,都会产生一个子目录,里面会有一个gmon.out文件,防止后续分析的时候搞混了。

step 5:用gprof工具分析$PGDATA/gprof对应进程的gmon.out


[gd@intel175 gprof]$ ll
total 20
drwx------ 2 gd gd 4096 Aug  8 11:34 29072
drwx------ 2 gd gd 4096 Aug  8 11:34 29073
drwx------ 2 gd gd 4096 Aug  8 11:26 7956
drwx------ 2 gd gd 4096 Aug  8 11:26 7957
drwx------ 2 gd gd 4096 Aug  7 14:54 avworker
[gd@intel175 gprof]$ gprof -b ~/app/bin/postgres 7957/gmon.out > pg.out
[gd@intel175 gprof]$ gprof -b ~/app/bin/postgres 29073/gmon.out > ora.out    
[gd@intel175 gprof]$ pwd
/data/gd/data_oracle/gprof
[gd@intel175 gprof]$ ls
29072  29073  7956  7957  avworker  ora.out  pg.out
[gd@intel175 gprof]$ ll
total 3672
drwx------ 2 gd gd    4096 Aug  8 11:34 29072
drwx------ 2 gd gd    4096 Aug  8 11:34 29073
drwx------ 2 gd gd    4096 Aug  8 11:26 7956
drwx------ 2 gd gd    4096 Aug  8 11:26 7957
drwx------ 2 gd gd    4096 Aug  7 14:54 avworker
-rw-rw-r-- 1 gd gd 1856581 Aug  8 15:56 ora.out
-rw-rw-r-- 1 gd gd 1879224 Aug  8 15:55 pg.out

gprof参数说明:

[gd@intel175 gprof]$ gprof  --h
Usage: gprof [-[abcDhilLsTvwxyz]] [-[ACeEfFJnNOpPqSQZ][name]] [-I dirs]
        [-d[num]] [-k from/to] [-m min-count] [-t table-length]
        [--[no-]annotated-source[=name]] [--[no-]exec-counts[=name]]
        [--[no-]flat-profile[=name]] [--[no-]graph[=name]]
        [--[no-]time=name] [--all-lines] [--brief] [--debug[=level]]
        [--function-ordering] [--file-ordering] [--inline-file-names]
        [--directory-path=dirs] [--display-unused-functions]
        [--file-format=name] [--file-info] [--help] [--line] [--min-count=n]
        [--no-static] [--print-path] [--separate-files]
        [--static-call-graph] [--sum] [--table-length=len] [--traditional]
        [--version] [--width=n] [--ignore-non-functions]
        [--demangle[=STYLE]] [--no-demangle] [--external-symbol-table=name] [@FILE]
        [image-file] [profile-file...]
-b 不再输出统计图表中每个字段的详细描述。
-p 只输出函数的调用图(Call graph的那部分信息)。
-q 只输出函数的时间消耗列表。
-e Name 不再输出函数Name 及其子函数的调用图(除非它们有未被限制的其它父函数)。可以给定多个 -e 标志。一个 -e 标志只能指定一个函数。
-E Name 不再输出函数Name 及其子函数的调用图,此标志类似于 -e 标志,但它在总时间和百分比时间的计算中排除了由函数Name 及其子函数所用的时间。
-f Name 输出函数Name 及其子函数的调用图。可以指定多个 -f 标志。一个 -f 标志只能指定一个函数。
-F Name 输出函数Name 及其子函数的调用图,它类似于 -f 标志,但它在总时间和百分比时间计算中仅使用所打印的例程的时间。可以指定多个 -F 标志。一个 -F 标志只能指定一个函数。-F 标志覆盖 -E 标志。
-z 显示使用次数为零的例程(按照调用计数和累积时间计算)。
一般用法: gprof –b 二进制程序 gmon.out 重定向到一个文件中,便于查看。   

step 6:如何查看gprof工具生成出来的报告


gprof 产生的Flat profile解释:

参数名称 解释
%time 该函数消耗时间占程序所有时间百分比
cumulative seconds 程序的累积执行时间,只是包括gprof能够监控到的函数
self seconds 该函数本身执行时间,所有被调用次数的合共时间
calls 函数被调用次数
selfs/call 函数平均执行时间,不包括被调用时间
totals/call 函数平均执行时间,包括被调用时间
name 函数名称
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls   s/call   s/call  name    
 45.12     18.71    18.71 13421919     0.00     0.00  AllocSetCheck
 19.05     26.61     7.90 469003493     0.00     0.00  sentinel_ok
  1.47     27.22     0.61  2033817     0.00     0.00  hash_search_with_hash_value
  1.18     27.71     0.49  2733737     0.00     0.00  _bt_compare
  1.17     28.20     0.49    46832     0.00     0.00  MemoryContextCheck
  1.12     28.66     0.47  6712659     0.00     0.00  set_sentinel
  1.05     29.10     0.44 10318963     0.00     0.00  AllocSetAlloc
  0.60     29.35     0.25  2509962     0.00     0.00  SearchCatCache
  0.58     29.59     0.24  1189158     0.00     0.00  palloc0
  0.51     29.80     0.21   131790     0.00     0.00  pg_encoding_mbcliplen
  0.48     30.00     0.20   796349     0.00     0.00  slot_deform_tuple
  0.46     30.19     0.19 14221223     0.00     0.00  AllocSetFreeIndex

Call Graph 的字段含义:

参数名称 解释
index 索引值
%time 函数消耗时间占所有时间百分比
self 函数本身执行时间
children 执行子函数所用时间
called 被调用次数
name 函数名称

                        Call graph


granularity: each sample hit covers 2 byte(s) for 0.02% of 41.47 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]     98.7    0.00   40.92                 main [1]
                0.00   40.92       1/1           PostmasterMain [2]
                0.00    0.00       1/1           MemoryContextInit [1751]
                0.00    0.00       6/6           init_locale [1864]
                0.00    0.00       1/1           set_pglocale_pgservice [1866]
                0.00    0.00       1/1           get_progname [3175]
                0.00    0.00       1/1           startup_hacks [3206]
                0.00    0.00       1/1           save_ps_display_args [3196]
                0.00    0.00       1/2           check_strxfrm_bug [3002]
                0.00    0.00       1/1           check_root [3163]
-----------------------------------------------

测试结论


通过gprof生成出来的单进程性能分析报告发现,单进程下pg语法及oracle语法下,TOP10函数没太大区别。在多并发的场景下才会有明显差别,还是得通过高并发场景来分析性能瓶颈。
这里写图片描述

开源url:https://github.com/ADBSQL/AntDB
QQ交流群:496464280

猜你喜欢

转载自blog.csdn.net/u011098015/article/details/81507399