-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRocksDB_Benchmark.scala
229 lines (209 loc) · 7.13 KB
/
RocksDB_Benchmark.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package swaydb.benchmark.readwrite
import java.nio.file.{Files, Paths}
import org.rocksdb.{RocksDB, _}
import swaydb.benchmark.readwrite.CommonSettings._
import swaydb.benchmark.util.FileUtils
import swaydb.core.util.Benchmark
import scala.util.Random
/**
* The following benchmarks RocksDB's put, get and iteration
*
* The goal is to keep the default configuration of RocksDB since it's already
* tuned for performance and configure [[SwayDB_Benchmark]] such that they
* both generate same size data files, so that the benchmarks are fair.
*/
object RocksDB_Benchmark extends App {
val dir = Paths.get("target").resolve("dbs").resolve(this.getClass.getSimpleName.takeWhile(_ != '$'))
if (Files.notExists(dir)) Files.createDirectories(dir)
//Following the documentationhttps://github.com/facebook/rocksdb/wiki/RocksJava-Basics#opening-a-database
//this initialises RocksDB with default configuration.
RocksDB.loadLibrary()
val options: Options = new Options().setCreateIfMissing(true)
options.setCreateIfMissing(true)
.setCompressionType(CompressionType.NO_COMPRESSION)
.setCompactionStyle(CompactionStyle.LEVEL)
//Reading https://github.com/facebook/rocksdb/wiki/IO#memory-mapping?
.setAllowMmapWrites(mmap)
.setAllowMmapReads(mmap)
val tableConfig = new BlockBasedTableConfig()
tableConfig.setDataBlockIndexType(DataBlockIndexType.kDataBlockBinarySearch)
options.setTableFormatConfig(tableConfig)
var db: RocksDB = _
try {
db = RocksDB.open(options, dir.toString)
/**
* Comment out any of the following to disable specific benchmarking.
*
* The benchmark results were generated running each test independently
* and not by running them all.
*/
runWriteBenchmark()
// runGetBenchmark()
// runForwardIteratorBenchmark()
// runReverseIteratorBenchmark()
} finally {
db.closeE()
}
/**
* Benchmark outcome
*
* Setting MMAP to true does not seems to improve write performance, not sure why.
* Reference - https://github.com/facebook/rocksdb/wiki/IO#memory-mapping?
*
* SST files size: 209.28 mb - 209276128 bytes
*
* 8 SST files
*
* Sequential writes when MMAP = true
* 45.813645809 seconds - RocksDB write benchmark
* 50.508779181 seconds - RocksDB write benchmark
* 45.266165614 seconds - RocksDB write benchmark
* 47.660416393 seconds - RocksDB write benchmark
* 45.503487944 seconds - RocksDB write benchmark
*
* Sequential writes when MMAP = false
* 46.395437331 seconds - RocksDB write benchmark
* 49.042667069 seconds - RocksDB write benchmark
* 47.568988724 seconds - RocksDB write benchmark
* 46.659120858 seconds - RocksDB write benchmark
* 48.190332371 seconds - RocksDB write benchmark
*
* Random writes when MMAP = true
* 63.596482965 seconds - RocksDB write benchmark
* 62.331631868 seconds - RocksDB write benchmark
* 64.550185832 seconds - RocksDB write benchmark
* 63.649219735 seconds - RocksDB write benchmark
* 64.820218425 seconds - RocksDB write benchmark
*
* Random writes when MMAP = false
* 64.131865702 seconds - RocksDB write benchmark
* 67.310220168 seconds - RocksDB write benchmark
* 64.91836709 seconds - RocksDB write benchmark
* 62.431859886 seconds - RocksDB write benchmark
* 68.371243788 seconds - RocksDB write benchmark
*/
def runWriteBenchmark(): Unit = {
val keyValuesToWrite =
if (randomPut)
Random.shuffle(keyValues)
else
keyValues
Benchmark(s"RocksDB write benchmark") {
keyValuesToWrite foreach {
case (key, value) =>
db.put(key, value)
}
}
//print the disk space taken by all sst files.
FileUtils.printFilesSize(dir, "sst")
}
/**
* SEQUENTIAL READS
*
* Round 1
* 18.542748423 seconds - 1 - RocksDB get benchmark
* 17.714711606 seconds - 2 - RocksDB get benchmark
* 18.429583195 seconds - 3 - RocksDB get benchmark
*
* Round 2
* 19.931010065 seconds - 1 - RocksDB get benchmark
* 18.099922013 seconds - 2 - RocksDB get benchmark
* 18.322394244 seconds - 3 - RocksDB get benchmark
*
* Round 3
* 18.338736555 seconds - 1 - RocksDB get benchmark
* 20.713966147 seconds - 2 - RocksDB get benchmark
* 18.321136763 seconds - 3 - RocksDB get benchmark
*
* RANDOM READS
*
* Round 1
* 87.591932011 seconds - 1 - RocksDB get benchmark.
* 88.467268891 seconds - 2 - RocksDB get benchmark.
* 88.010611396 seconds - 3 - RocksDB get benchmark.
*
* Round 2
* 92.670774118 seconds - 1 - RocksDB get benchmark.
* 90.353062746 seconds - 2 - RocksDB get benchmark.
* 91.179779257 seconds - 3 - RocksDB get benchmark.
*
* Round 3
* 90.38328082 seconds - 1 - RocksDB get benchmark.
* 90.616760827 seconds - 2 - RocksDB get benchmark.
* 91.841050684 seconds - 3 - RocksDB get benchmark.
*/
def runGetBenchmark(): Unit = {
val keyVals =
if (randomGet)
Benchmark("Shuffling key-values")(Random.shuffle(keyValues))
else
keyValues
FileUtils.printFilesSize(dir, "sst")
(1 to 3) foreach {
count =>
Benchmark(s"$count - RocksDB get benchmark") {
keyVals foreach {
case (key, _) =>
db.get(key)
}
}
}
}
/**
* Round 1
* 6.250122786 seconds - 1 - RocksDB forward iterator benchmark.
* 3.933878549 seconds - 2 - RocksDB forward iterator benchmark.
* 3.9904791 seconds - 3 - RocksDB forward iterator benchmark.
*
* Round 2
* 4.211968881 seconds - 1 - RocksDB forward iterator benchmark.
* 6.505442164 seconds - 2 - RocksDB forward iterator benchmark.
* 3.955146595 seconds - 3 - RocksDB forward iterator benchmark.
*
* Round 2
* 6.334389409 seconds - 1 - RocksDB forward iterator benchmark.
* 3.869475149 seconds - 2 - RocksDB forward iterator benchmark.
* 3.969485287 seconds - 3 - RocksDB forward iterator benchmark.
*/
def runForwardIteratorBenchmark(): Unit =
(1 to 3) foreach {
count =>
Benchmark(s"$count - RocksDB forward iterator benchmark") {
val iterator = db.newIterator()
iterator.seekToFirst()
keyValues foreach {
_ =>
iterator.key()
iterator.value()
iterator.next()
}
iterator.close()
}
}
/**
* Round 1
* 6.887790127 seconds - 1 - RocksDB reverse iterator benchmark.
* 4.773549085 seconds - 2 - RocksDB reverse iterator benchmark.
* 4.426286691 seconds - 3 - RocksDB reverse iterator benchmark.
*
* Round 2
* 6.492809259 seconds - 1 - RocksDB reverse iterator benchmark.
* 4.634335185 seconds - 2 - RocksDB reverse iterator benchmark.
* 4.864573025 seconds - 3 - RocksDB reverse iterator benchmark.
*/
def runReverseIteratorBenchmark(): Unit =
(1 to 3) foreach {
count =>
Benchmark(s"$count - RocksDB reverse iterator benchmark") {
val iterator = db.newIterator()
iterator.seekToLast()
keyValues foreach {
_ =>
iterator.key()
iterator.value()
iterator.prev()
}
iterator.close()
}
}
}