Resources:
- YCSB GitHub Address: Https://github.com/brianfrankcooper/YCSB
- Wiki:https://github.com/brianfrankcooper/ycsb/wiki
- Installation reference: Https://github.com/brianfrankcooper/YCSB/tree/master/mongodb
- Some previous Test experience: http://www.sdpnosql.net/index.php/archives/3/http://www.sdpnosql.net/index.php/archives/13/
1 installation
Install JAVA,MVN,YCSB based on a reference document (HTTPS://GITHUB.COM/BRIANFRANKCOOPER/YCSB/TREE/MASTER/MONGODB)
Python is basically installed (2.7.5 version above), Java (requires JDK, not JRE), MVN and YCSB.
1.1 YCSB directory Structure
After installing YCSB, view the YCSB directory as follows:
1234567891011121314151617181920212223242526272829303132 |
drwxr-xr-x. 3 root root 30 Oct 10 18:20 accumulo
drwxr-xr-x. 3 root root 46 Oct 10 18:20 aerospike
drwxr-xr-x. 2 root root 17 Oct 13 05:03 bin
drwxr-xr-x. 3 root root 56 Oct 10 18:20 binding-parent
-rw-r--r--. 1 root root 877 Oct 10 18:20 BUILD
drwxr-xr-x. 3 root root 30 Oct 10 18:20 cassandra
-rw-r--r--. 1 root root 7216 Oct 10 18:20 checkstyle.xml
drwxr-xr-x. 4 root root 60 Oct 13 03:18 core
drwxr-xr-x. 3 root root 46 Oct 10 18:20 couchbase
drwxr-xr-x. 3 root root 30 Oct 10 18:20 distribution
drwxr-xr-x. 4 root root 4096 Oct 10 18:20 doc
drwxr-xr-x. 4 root root 54 Oct 10 18:20 dynamodb
drwxr-xr-x. 3 root root 46 Oct 10 18:20 elasticsearch
drwxr-xr-x. 3 root root 30 Oct 10 18:20 gemfire
drwxr-xr-x. 2 root root 36 Oct 10 18:20 hbase094
drwxr-xr-x. 3 root root 46 Oct 10 18:20 hbase098
drwxr-xr-x. 3 root root 46 Oct 10 18:20 hbase10
drwxr-xr-x. 3 root root 43 Oct 10 18:20 hypertable
drwxr-xr-x. 3 root root 46 Oct 10 18:20 infinispan
drwxr-xr-x. 3 root root 30 Oct 10 18:20 jdbc
-rw-r--r--. 1 root root 8082 Oct 10 18:20 LICENSE.txt
drwxr-xr-x. 3 root root 43 Oct 10 18:20 mapkeeper
drwxr-xr-x. 4 root root 59 Oct 13 03:19 mongodb
drwxr-xr-x. 3 root root 43 Oct 10 18:20 nosqldb
-rw-r--r--. 1 root root 479 Oct 10 18:20 NOTICE.txt
drwxr-xr-x. 3 root root 46 Oct 10 18:20 orientdb
-rw-r--r--. 1 root root 5263 Oct 10 18:20 pom.xml
-rw-r--r--. 1 root root 2033 Oct 10 18:20 README.md
drwxr-xr-x. 3 root root 46 Oct 10 18:20 redis
drwxr-xr-x. 3 root root 46 Oct 10 18:20 tarantool
drwxr-xr-x. 3 root root 30 Oct 10 18:20 voldemort
drwxr-xr-x. 2 root root 4096 Oct 13 01:09 workloads
|
Here are a few directories to be aware of:
bin: - 目录下有个可执行的ycsb文件,是个python脚本,是用户操作的命令行接口。ycsb主逻辑是:解析命令行、设置java环境,加载java-libs,封装成可以执行的java命令,并执行workloads: - 目录下有各种workload的模板,可以基于workload模板进行个性化修改core: - 包含ycsb里各种核心实现,比如DB的虚拟类DB.java,各个db子类都要继承该类;还有比如workload抽象类,如果我们要自定义workload实现也需要继承该类各种DB的目录: - 比如mongo,redis等,里面包含了对应测试的源码等。 - 当ycsb mvn编译后,会在对应的目录下生成target文件,ycsb会加载对应target文件中的class类
2 use
YCSB is implemented in two stages: the load phase and the transaction phase
2.1 Load Phase
This phase is mainly used to construct the test data, and the YCSB will construct the data required for the test in DB based on the parameter setting, such as:
1 |
. /bin/ycsb load mongodb-async -s -P workloads /workloada > outputLoad.txt |
Mongodb-async
In YCSB, there are options for different db, such as MONGO with MongoDB and Mongodb-async.
The default MongoDB represents synchronization, that is, load and run use synchronization, YCSB will call mongodb/src under the corresponding mongodbclient to implement the corresponding insert/update and other operations. If MONGODB-ASYNC,YCSB is set, the corresponding Asyncmongodbclient.java implementation under MONGODB/SRC is called
Parameter settings:
12345678 |
Options:
-P
file
Specify workload
file
//
workload文件
-
cp
path Additional Java classpath entries
-jvm-args args Additional arguments to the JVM
-p key=value Override workload property
//
一些设置
-s Print status to stderr
//
把状态达到stderr中
-target n Target ops
/sec
(default: unthrottled)
//
每秒总共操作的次数
-threads n Number of client threads (default: 1)
//
客户端线程数
|
Parameter interpretation:
-P Workload File
In the YCSB directory there are various workload, reference: Https://github.com/brianfrankcooper/YCSB/wiki/Core-Workloads, we take the example of Workloada
Basic configuration:
123456789101112 |
recordcount=1000& nbsp; # total number of operation bars # total number of operations readallfields= Code class= "Bash functions" >true # read all fields are required < Code class= "Bash Plain" >readproportion=0.5 # read scale updateproportion=0.5 # Update scale scanproportion=0 insertproportion=0 requestdistribution=zipfian |
Workloada load comparison, read and update class ratio is 1:1, some of the settings parameters such as above, if we set MONGO again, also need to add the corresponding MONGO configuration workload, as follows:
123 |
mongodb.url=mongodb: //192 .168.137.10:34001 /ycsb ? # mongodb对应的uri等 mongodb.database=ycsb # 对应的db mongodb.writeConcern=normal # 写级别 |
-P option
-P is used to set some corresponding parameters, if the parameters in the workload, you can also put on the command line as-p set
-S
-S is indicated, in the run, to print some status to stderr, general status information, used to indicate some intermediate states in the run (such as how many requests are currently processed, how many requests, etc.)
-target N
Represents the total number of operations in 1s (each thread adds up), if the performance is not satisfied, such as the maximum performance of only 100, you set 1000, then YCSB will try to approach this number. The default is no limit.
-thread Number of threads
Set the number of concurrent test threads for the YCSB client, the default is 1, single-threaded, so when testing again, be sure to set this option
2.2 Transcation Stage
At the end of 2.1load data, YCSB can be tested, which is the transaction phase. In the transaction phase, the DB pressure is measured based on the scale setting in the workload and the thread parameter settings. Specific parameters above
3 Some Custom Actions
Because this time in the use of YCSB test MongoDB is mainly to test the performance of mongodb3.0, but also need to compare with 2.6.9. The 3.0 performance write performance is greatly improved because the lock force is upgraded from DB Lock to collection lock. The default insert and update operations are for the same collection operation (usertable), which does not reflect this advantage.
So we need to modify the corresponding insert, update, and read interfaces to write multiple db at once. Modify the following:
修改mongodb底下的MongoDbClient和AsyncMongoDbClient中关于insert、update、read函数实现如下:原来的实现:
12345678910111213141516171819 |
public final int update(final String table, final String key,
final HashMap<String, ByteIterator> values) {
try {
final MongoCollection collection = database.getCollection(table);
final DocumentBuilder query = BuilderFactory.start().add(
"_id"
, key);
final DocumentBuilder update = BuilderFactory.start();
final DocumentBuilder fieldsToSet = update.push(
"$set"
);
for
(final Map.Entry<String, ByteIterator> entry : values.entrySet()) {
fieldsToSet.add(entry.getKey(), entry.getValue().toArray());
}
final long res =
collection.update(query, update,
false
,
false
, writeConcern);
return
res == 1 ? 0 : 1;
} catch (final Exception e) {
System.err.println(e.toString());
return
1;
}
}
|
修改后:
1 |
public
final
int
update(
final
String table,
final
String key,
final
HashMap<String, ByteIterator> values) {<br>
Make changes to the original update function, and do a few more operations on each update <br> int ret = updateonetable (table, key, values); <br > if (ret! = 0) {<br> return ret;<br> }<br> <br> for (int i = 0; i < table_num; ++i) {< br> String tableName = table + string.valueof (i);<br> ret = updateonetable (tableName, key, values);<br> if (ret! = 0) {<br> Return ret;<br> }<br> } <br> <br> return 0; <br>} <br><br>public final int updateonetable (final string table, final string key, final hashmap<st Ring, byteiterator> values) {<br> try {<br> final mongocollection Collection = database.getcollection (table);<br> final Documentbuilder query = Builderfactory.start (). Add ("_id", key);<br> Final Documentbuilder update = Builderfactory.start ();<br> Final Documentbuilder Fieldstoset = Update.push ("$set");<br> <br > for (final map.entry<string, byteiterator> Entry: Values.entryset ()) {<br> Fieldstoset.add (Entry.getkey (), Entry.getvalue (). ToArray ()); <br> }<br> <br> Final Long res = collection.update (query, update, FALSE, False, WRiteconcern);<br> return res = = 1? 0:1; <br> catch (Final Exception e) {<br> System.err.println (E.tostring ()); return 1; <br> } <br>} |
Where table_num can be set according to actual requirements (in practice, we set this value to 4, which means write 5 table at a time)
[OVERALL], RunTime (ms), 704740.0 #执行时间
[OVERALL], throughput (ops/sec), 1418.9630218236514# operand per second, throughput
[CLEANUP], Operations, 100.0
[CLEANUP], averagelatency (US), 279.56
[CLEANUP], minlatency (US), 0.0
[CLEANUP], maxlatency (US), 27823.0
[CLEANUP], 95thPercentileLatency (US), 2.0
[CLEANUP], 99thPercentileLatency (US), 18.0
[INSERT], Operations, 50147.0#insert operand
[INSERT], averagelatency (US), 69745.87736055996#insert average operating time
[INSERT], minlatency (US), 461.0#insert min. Operation time
[INSERT], maxlatency (US), 3080191.0#insert maximum operating time
[INSERT], 95thPercentileLatency (US), 138623.0#insert 95% operation time
[INSERT], 99thPercentileLatency (US), 150911.0#insert 99% operation time
[INSERT], Return=ok, 50147#insert successful number of operations
[READ], Operations, 949853.0
[READ], averagelatency (US), 70395.02938033569
[READ], minlatency (US), 262.0
[READ], maxlatency (US), 3135487.0
[READ], 95thPercentileLatency (US), 138751.0
[READ], 99thPercentileLatency (US), 151039.0
[READ], Return=ok, 675134
[READ], Return=not_found, 274719
"Go" Test MongoDB with YCSB