随着信息化规划的全面推进和企业级信息系统一体化建设不断完善,信息基础设施和软硬件快速扩充,信息系统复杂度大幅提高,数据量呈几何倍数急剧增长,集中式数据中心、大规模数据容灾中心建设,结构化与非结构化数据存储扩容等使电力企业信息逐步显现出大容量、多种类、快速处理和高时效性的特征。而应用系统一贯采用的传统关系型数据库(RDBMS)在应付海量数据、大规模用户、高并发、web2.0网站等方面显得力不从心,难以满足大数据的处理需求。
为了引入内存数据库技术,为研究确保数据的持久性和高可用性为前提,满足高并发、高时效的应用需要,需要研究内存库性能,对比TimesTen与Oracle的TPS、对比相同SQL在TimesTen与Oracle的执行效率,研究TimesTen内存库的并发能力。TimesTen内存数据库的性能远远高于传统的大型关系数据库,不单是因为数据全部保存在内存中和数据处于应用程序层,更重要的是TimesTen内存数据库拥有更优化的算法和更少的CPU开销,这个在电信行业已经得到很好的验证,本节主要研究在项目中TimesTen内存库的性能。本文档为内存库技术研究与应用项目性能研究,仅供技术参考。
术语定义:缩写 | 全称/定义 |
TT | TimesTen内存数据库 |
TPS | Transaction Per second |
Demo | TT自带的性能对比工具 |
主节点 | 互为主备模式内存库的主节点 |
备节点 | 互为主备模式内存库的备节点 |
研究项目 | 研究项目内容说明 |
TT和Oracle的TPS | 研究不同线程、不同数据量分别采用查询、插入、混合DML对比TT和Oracle的TPS。 |
TT和Oracle的SQL效能 | 采用业务表及业务SQL,模仿真实业务,通过直接在TT和Oracle端执行业务SQL语句,对比TT和Oracle的执行效能。 |
|
|
数据量 |
插入10000行记录 |
插入250000行记录 |
插入1000000行记录 |
|||
次序 |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
1 |
16835 |
3880 |
17634 |
4418 |
18030 |
4376 |
2 |
16722 |
4180 |
17510 |
3946 |
17324 |
4314 |
3 |
16722 |
2912 |
18222 |
4079 |
19968 |
4225 |
4 |
16920 |
4323 |
19066 |
4164 |
17225 |
4275 |
5 |
16722 |
4133 |
17386 |
4183 |
17145 |
4306 |
6 |
16891 |
4100 |
17763 |
3893 |
17381 |
4385 |
7 |
16949 |
4323 |
17621 |
4448 |
16868 |
4157 |
8 |
16778 |
4273 |
17639 |
4108 |
18484 |
4140 |
9 |
17241 |
4297 |
17687 |
3970 |
17924 |
4218 |
10 |
16891 |
4302 |
17626 |
3942 |
17796 |
4336 |
11 |
16750 |
4432 |
17798 |
4184 |
18337 |
4176 |
12 |
16920 |
4317 |
17480 |
4477 |
19507 |
4214 |
13 |
16666 |
4327 |
17563 |
4135 |
17066 |
4331 |
14 |
16977 |
4214 |
17652 |
4150 |
17179 |
4344 |
15 |
16891 |
4093 |
17636 |
4371 |
20046 |
4191 |
16 |
17152 |
4291 |
17562 |
4720 |
17198 |
4341 |
17 |
17152 |
4297 |
17667 |
3997 |
19011 |
4231 |
18 |
16750 |
4332 |
17750 |
4092 |
17507 |
4474 |
19 |
16750 |
2494 |
17709 |
4245 |
16917 |
4277 |
20 |
16891 |
4340 |
17461 |
4378 |
17131 |
4265 |
平均值TPS |
16879 |
4093 |
17722 |
4195 |
17902 |
4279 |
语句数量 |
每个事务1条语句 |
每个事务5条语句 |
每个事务10条语句 |
|||
次序 |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
1 |
6711 |
2369 |
2577 |
789 |
1230 |
430 |
2 |
6622 |
2375 |
2604 |
803 |
1488 |
436 |
3 |
6666 |
2320 |
2617 |
798 |
1499 |
432 |
4 |
6666 |
2358 |
2617 |
809 |
1494 |
439 |
5 |
6666 |
2336 |
2583 |
793 |
1481 |
446 |
6 |
6756 |
2481 |
2583 |
761 |
1212 |
407 |
7 |
6666 |
2439 |
2617 |
745 |
1490 |
440 |
8 |
6711 |
1567 |
2652 |
798 |
1499 |
450 |
9 |
6622 |
2132 |
2590 |
787 |
1485 |
418 |
10 |
6666 |
2380 |
2645 |
802 |
1468 |
449 |
11 |
6666 |
2207 |
2610 |
801 |
1221 |
441 |
12 |
6578 |
2352 |
2577 |
764 |
1481 |
452 |
13 |
6666 |
2427 |
2638 |
724 |
1539 |
441 |
14 |
6578 |
2415 |
2583 |
771 |
1422 |
426 |
15 |
6578 |
1953 |
2577 |
787 |
1497 |
444 |
16 |
6578 |
2331 |
2570 |
794 |
1490 |
440 |
17 |
6849 |
2386 |
2610 |
634 |
1582 |
445 |
18 |
6849 |
2380 |
2590 |
783 |
1488 |
445 |
19 |
6756 |
2347 |
2597 |
795 |
1499 |
309 |
20 |
6756 |
2237 |
2570 |
793 |
1485 |
441 |
平均值 |
6680 |
2290 |
2600 |
777 |
1453 |
432 |
语句数量 |
每个事务1条语句 |
每个事务5条语句 |
每个事务10条语句 |
|||
次序 |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
1 |
21276 |
10030 |
8880 |
2891 |
5271 |
1530 |
2 |
20576 |
10141 |
9225 |
3078 |
5763 |
1527 |
3 |
22321 |
5813 |
9523 |
1992 |
5665 |
1470 |
4 |
23584 |
10504 |
8888 |
3439 |
5633 |
1399 |
5 |
23148 |
10214 |
9293 |
2653 |
5602 |
1218 |
6 |
24038 |
11389 |
8620 |
3254 |
5219 |
1462 |
7 |
22831 |
11627 |
7794 |
3032 |
5078 |
1526 |
8 |
22471 |
10582 |
8710 |
3195 |
5672 |
1532 |
9 |
19723 |
11574 |
8688 |
3060 |
5720 |
1464 |
10 |
24390 |
10695 |
8726 |
3089 |
5617 |
1451 |
11 |
16086 |
11363 |
9082 |
3007 |
5408 |
1355 |
12 |
20790 |
11682 |
9250 |
3062 |
5411 |
1474 |
13 |
23201 |
10869 |
8319 |
3132 |
5707 |
1411 |
14 |
20703 |
10193 |
8912 |
2921 |
5681 |
1504 |
15 |
22675 |
10449 |
8613 |
2138 |
5632 |
1046 |
16 |
23094 |
12135 |
8771 |
3209 |
5753 |
1280 |
17 |
24213 |
10298 |
8665 |
2839 |
5500 |
1573 |
18 |
21367 |
10416 |
9216 |
2843 |
5373 |
1525 |
19 |
23255 |
9532 |
7320 |
2982 |
5611 |
1607 |
20 |
25188 |
10683 |
9416 |
2909 |
5681 |
1508 |
平均值 |
22247 |
10509 |
8796 |
2936 |
5550 |
1443 |
数据量 |
DML操作10000行记录 |
DML操作250000行记录 |
DML操作1000000行记录 |
|||
次序 |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
TPS(TT) |
TPS(Oracle) |
1 |
21621 |
7380 |
21917 |
2358 |
21978 |
4700 |
2 |
18561 |
5822 |
21739 |
6914 |
21164 |
6944 |
3 |
21621 |
1852 |
14842 |
6914 |
21333 |
5578 |
4 |
14440 |
7332 |
19851 |
7252 |
20887 |
7194 |
5 |
16405 |
7168 |
19801 |
6908 |
20408 |
6130 |
6 |
16405 |
7067 |
21505 |
5502 |
18475 |
7414 |
7 |
20565 |
6509 |
21108 |
3016 |
21563 |
7029 |
8 |
21917 |
6902 |
20050 |
6562 |
21857 |
7092 |
9 |
21276 |
7292 |
20100 |
6785 |
20151 |
6274 |
10 |
21798 |
7421 |
22408 |
6920 |
15209 |
7326 |
11 |
22857 |
6225 |
21390 |
3304 |
14545 |
7319 |
12 |
19370 |
7213 |
20408 |
7060 |
19093 |
6405 |
13 |
18648 |
5714 |
19950 |
6785 |
20304 |
7292 |
14 |
19323 |
4162 |
14953 |
6980 |
21680 |
6938 |
15 |
21447 |
3481 |
18018 |
5305 |
14787 |
6968 |
16 |
21220 |
6962 |
17897 |
1874 |
22038 |
6896 |
17 |
20833 |
5904 |
19900 |
6216 |
22222 |
6369 |
18 |
18518 |
7285 |
14388 |
7239 |
22535 |
3154 |
19 |
20833 |
7011 |
18779 |
2093 |
14209 |
6206 |
20 |
22346 |
6785 |
21447 |
5606 |
21390 |
3868 |
平均值 |
20000 |
6274 |
19523 |
5580 |
19791 |
6355 |
SQL序号 |
Oracle耗时 |
TT耗时 |
结果集 |
结果集大小KB |
结果集大小MB |
1 |
0.11 |
0.09 |
544424 |
81920 |
80 |
2 |
0.91 |
0.03 |
205474 |
57344 |
56 |
3 |
0.02 |
0.01 |
70944 |
11264 |
11 |
4 |
0.04 |
0.01 |
50808 |
27648 |
27 |
5 |
1.91 |
0.03 |
410928 |
114688 |
112 |
6 |
20.56 |
10.12 |
544424 |
81920 |
80 |
7 |
16.14 |
3.72 |
205474 |
57344 |
56 |
8 |
2.63 |
1.28 |
70944 |
11264 |
11 |
9 |
7.76 |
0.99 |
50808 |
27648 |
27 |
10 |
26.64 |
3.78 |
410928 |
114688 |
112 |
平均值 |
7.672 |
2.01 |
256515.6 |
58572.8 |
57.2 |
SQL序号 |
Oracle耗时 |
TT耗时 |
结果集 |
结果集大小KB |
结果集大小MB |
11 |
0.64 |
0.47 |
70944 |
10675 |
10 |
12 |
7.43 |
1.63 |
28743 |
8022 |
8 |
13 |
1.16 |
1.21 |
14398 |
2294 |
2 |
14 |
3.52 |
1.3 |
186211 |
29565 |
29 |
15 |
1.32 |
0.4 |
244128 |
38900 |
38 |
16 |
28.58 |
24.54 |
544424 |
81920 |
80 |
17 |
16.92 |
14.08 |
205474 |
57344 |
56 |
18 |
22.56 |
20.5 |
708222 |
114688 |
112 |
19 |
6.83 |
4.31 |
70944 |
11264 |
11 |
20 |
8.07 |
5.81 |
239148 |
48128 |
47 |
平均值 |
9.70 |
7.43 |
231264 |
40280 |
39.3 |
2. 设置数据库和帐号
$ ttversion
TimesTen Release 11.2.2.7.0 (64 bit Linux/x86_64) (tt1122:53396) 2014-12-23T09:26:28Z
Instance admin: oracle
Instance home directory: /home/oracle/TimesTen/tt1122
Group owner: oinstall
Daemon home directory: /home/oracle/TimesTen/tt1122/info
PL/SQL enabled.
3. 设置环境变量
$ cd quickstart/sample_scripts/createdb
$ ./build_sampledb.sh
4. 编译基准测试程序
$ . quickstart/ttquickstartenv.sh
5. 运行基准测试程序, 查看测试程序的参数含义$ cd quickstart/sample_code/jdbc
$ javac Tptbm.java
6. 建立测试的基础数据,插入10000条记录,使用Hash索引
$ java Tptbm -help
Usage: Tptbm [<-url url_string>] [-v <level>] [-threads <num_threads>] [-reads <read_%>] [-insert <insert_%>] [-delete<delete_%>] [-xacts <num_xacts>] [-min <min_xacts>] [-max <max_xacts>] [-seed <seed>] [-dbms <dbms_name>] [-CSCommit][-key <keys>] [-trace] [-nb | -build] [-h] [-help] [?]
-h Prints this message and exits.
-help Same as -h.
-url <url_string> Specifies JDBC url string of the database
to connect to
-threads <num_threads> Specifiesthe number of concurrent
threads. The default is 4.
-reads <read_%> Specifies the percentage of read-only
transactions. The default is 80.
-inserts <insert_%> Specifies the percentage of insert
transactions. The default is 0.
-deletes <delete_%> Specifies the percentage of delete
transactions. The default is 0.
-key <keys> Specifies the number of records (squared)
to initially populate in the data store.
The default value for keys is 100.
-xacts <xacts> Specifies the number of transactions
that each thread should run.
The default is 10000.
-seed <seed> Specifies the seed for the random
number generator.
-min <min_xacts> Minimum operations per transaction.
Default is 1.
-max <max_xacts> Maximum operations per transaction.
Default is 1.
Operations in a transaction randomly chosen
between min and max.
-multiop 1 insert, 3 selects, 1 update / transaction.
-dbms <dbms_name> Use timesten/oracle. Timesten is default
-CSCommit Turn on prefetchClose for client/server
-commitReads By default reads are not committed
-range Range rather than hash index
-plsql Use a PL/SQL procedure for -multiop
-trace Turns the JDBC tracing on
-nobuild Do not build the database
-build Builds database and exits
7. 运行测试,10个线程并发,每个线程运行1000个事务,每个事务2条语句,5% insert,5% delete, 20% update ,70% select
$ java Tptbm -build -key 100 -dbms timesten -url "jdbc:timesten:direct:dsn=sampledb_1122"
Connecting to the database ...
Enter password for ‘appuser‘:
Connected to database as appuser@jdbc:timesten:direct:dsn=sampledb_1122
Populating benchmark database ...
Database populated with 10000 rows in 689 ms (14513 TPS)
$ java Tptbm -nobuild -key 100 -inserts 5 -deletes 5 -reads 70 -threads 10 -xacts 1000 -min 2 -max 2 -dbms timesten -url"jdbc:timesten:direct:dsn=sampledb_1122"
Connecting to the database ...
Enter password for ‘appuser‘:
Begining execution with 10 thread(s): 70% read, 20% update, 5% insert, 5% delete
Elapsed Time: 781 ms
Transactions Per Sec: 12804
当每个事务的语句过多是,而基础记录比较少的时候,容易发生错误:TT6003: Lock request denied because of time-out,在TT中,LockWait的默认值是10秒(这个参数可以设成小数,例如0.1秒)
当测试中包含Insert或者是Delete,每次运行前必须要重新生成基础数据,否则如果有Insert则可能会有主键冲突的错误,如果有Delete,则由于记录数变少,则可能结果不准确。
9. 如果需要进行多次测试,为了避免每次输入密码的麻烦,可以在Tptbm.java代码的439行修改源代码为:
$ java Tptbm -nobuild -key 100 -multiop -threads 10 -xacts 1000 -dbms timesten -url "jdbc:timesten:direct:dsn=sampledb_1122"
Connecting to the database ...
Enter password for ‘appuser‘:
Begining execution with 10 thread(s): 60% read, 20% update, 20% insert, 0% delete
Elapsed Time: 2742 ms
Transactions Per Sec: 3646
10. 在Oracle中创建相关的用户
static private void getPassword() {
Tptbm.password = PasswordField.readPassword("Enter password for ‘appuser‘: ");
}
修改为:
static private void getPassword() {
Tptbm.password = "appuser";
}
在执行的时候就不需要输入密码了:例如
$ java Tptbm -build -key 100 -dbms timesten -url "jdbc:timesten:direct:dsn=sampledb_1122"
Connecting to the database ...
Connected to database as appuser@jdbc:timesten:direct:dsn=sampledb_1122
Populating benchmark database ...
Database populated with 10000 rows in 584 ms (17123 TPS)
11. 设置jdbc的CLASSPATH
$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.2.0 Production on Sat May 19 23:22:17 2012
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create user appuser identified by appuser;
User created.
SQL> grant connect, resource to appuser;
Grant succeeded.
SQL>
12. 在Oracle中生成基础数据
$ export CLASSPATH=$CLASSPATH:$ORACLE_HOME/jdbc/lib/ojdbc5.jar;
13. 运行测试,10个线程并发,每个线程运行1000个事务,每个事务2条语句,5% insert,5% delete, 20% update ,70% select
$ java Tptbm -build -key 100 -dbms oracle -url "jdbc:oracle:thin:@127.0.0.1:1521:orcl"
Connecting to the database ...
Connected to database as appuser@jdbc:oracle:thin:@127.0.0.1:1521:orcl
Populating benchmark database ...
Database populated with 10000 rows in 3592 ms (2783 TPS)
$ java Tptbm -nobuild -key 100 -inserts 5 -deletes 5 -reads 70 -threads 10 -xacts 1000 -min 2 -max 2 -dbms oracle -url"jdbc:oracle:thin:@127.0.0.1:1521:orcl"
Connecting to the database ...
Begining execution with 10 thread(s): 70% read, 20% update, 5% insert, 5% delete
Elapsed Time: 7676 ms
Transactions Per Sec
原文:http://blog.itpub.net/24930246/viewspace-1404777/