Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2022
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 KB | None | 0 0
  1. The benchmark compares the Besu implementation (patriciaMerkleTrie+rocksdb) with PatriciaDB.
  2.  
  3. The jobs inserts 40 batches of 100,000 key values (for a total of 4,000,000 keys).
  4. Each key/value is 32 bytes randomly generated.
  5.  
  6. Besu: time 3'45", final database size after compaction: 2.1GB
  7.  
  8. Batch 0 completed in 937
  9. Batch 1 completed in 1210
  10. Batch 2 completed in 1363
  11. Batch 3 completed in 1499
  12. Batch 4 completed in 1773
  13. Batch 5 completed in 1774
  14. Batch 6 completed in 2131
  15. Batch 7 completed in 2213
  16. Batch 8 completed in 2580
  17. Batch 9 completed in 2310
  18. Batch 10 completed in 2628
  19. Batch 11 completed in 2617
  20. Batch 12 completed in 2999
  21. Batch 13 completed in 3101
  22. Batch 14 completed in 3102
  23. Batch 15 completed in 3199
  24. Batch 16 completed in 4764
  25. Batch 17 completed in 4060
  26. Batch 18 completed in 3986
  27. Batch 19 completed in 3348
  28. Batch 20 completed in 3891
  29. Batch 21 completed in 3645
  30. Batch 22 completed in 5238
  31. Batch 23 completed in 10634
  32. Batch 24 completed in 9181
  33. Batch 25 completed in 6691
  34. Batch 26 completed in 6613
  35. Batch 27 completed in 5424
  36. Batch 28 completed in 13552
  37. Batch 29 completed in 9358
  38. Batch 30 completed in 8028
  39. Batch 31 completed in 6351
  40. Batch 32 completed in 6798
  41. Batch 33 completed in 12145
  42. Batch 34 completed in 10555
  43. Batch 35 completed in 9220
  44. Batch 36 completed in 9332
  45. Batch 37 completed in 14101
  46. Batch 38 completed in 10982
  47. Batch 39 completed in 10900
  48. Job completed in 224254
  49. Compaction time 12620
  50.  
  51.  
  52. PatriciaBD: 40 seconds, final database size (without compaction): 1.19GB
  53. Transaction 0 time 411
  54. Transaction 1 time 438
  55. Transaction 2 time 403
  56. Transaction 3 time 471
  57. Transaction 4 time 486
  58. Transaction 5 time 555
  59. Transaction 6 time 602
  60. Transaction 7 time 669
  61. Transaction 8 time 717
  62. Transaction 9 time 746
  63. Transaction 10 time 788
  64. Transaction 11 time 847
  65. Transaction 12 time 907
  66. Transaction 13 time 931
  67. Transaction 14 time 976
  68. Transaction 15 time 1028
  69. Transaction 16 time 1045
  70. Transaction 17 time 1075
  71. Transaction 18 time 1075
  72. Transaction 19 time 1095
  73. Transaction 20 time 1156
  74. Transaction 21 time 1173
  75. Transaction 22 time 1187
  76. Transaction 23 time 1190
  77. Transaction 24 time 1221
  78. Transaction 25 time 1241
  79. Transaction 26 time 1257
  80. Transaction 27 time 1289
  81. Transaction 28 time 1249
  82. Transaction 29 time 1228
  83. Transaction 30 time 1222
  84. Transaction 31 time 1237
  85. Transaction 32 time 1282
  86. Transaction 33 time 1275
  87. Transaction 34 time 1274
  88. Transaction 35 time 1353
  89. Transaction 36 time 1267
  90. Transaction 37 time 1263
  91. Transaction 38 time 1307
  92. Transaction 39 time 1257
  93. Total Time 40201
  94. Time: 40 seconds
  95.  
  96.  
  97.  
  98. Follows the code use to run a benchmark on Basu.
  99.  
  100.  
  101. File1:
  102.  
  103. package org.hyperledger.besu.ethereum.trie;
  104.  
  105.  
  106. import org.apache.tuweni.bytes.Bytes;
  107. import org.junit.jupiter.api.Test;
  108. import org.rocksdb.Options;
  109. import org.rocksdb.RocksDB;
  110. import org.rocksdb.RocksDBException;
  111.  
  112. import java.util.Random;
  113. import java.util.function.Function;
  114.  
  115. public class BesuPmtBenchmark {
  116.  
  117.  
  118. @Test
  119. public void runBenchmark() throws Exception{
  120.  
  121.  
  122. Random r= new Random(1);
  123. try (final Options options = new Options().setCreateIfMissing(true)) {
  124.  
  125. try (final RocksDB db = RocksDB.open(options, "/Users/xavix/temp/benchmark/rocksdb")) {
  126. BenchmarkRocksStorage myRockKVStorage = new BenchmarkRocksStorage(db);
  127. var merkleStorage = new KeyValueMerkleStorage(myRockKVStorage);
  128.  
  129. StoredMerklePatriciaTrie<Bytes, Bytes> s= new StoredMerklePatriciaTrie<>(merkleStorage::get, Function.identity(), Function.identity());
  130.  
  131. var rootHash = s.getRootHash();
  132. s.commit(merkleStorage::put);
  133.  
  134. byte[] key=new byte[32];
  135. byte[] value = new byte[32];
  136. long startTime = System.currentTimeMillis();
  137. for(int batch=0; batch< 40;batch++) {
  138. long batchStart = System.currentTimeMillis();
  139. StoredMerklePatriciaTrie<Bytes, Bytes> storage= new StoredMerklePatriciaTrie<>(merkleStorage::get,rootHash, Function.identity(), Function.identity());
  140. for(int i=0; i< 100_000; i++) {
  141. r.nextBytes(key);
  142. r.nextBytes(value);
  143. storage.put(Bytes.wrap(key), Bytes.wrap(value));
  144. }
  145. rootHash = storage.getRootHash();
  146. storage.commit(merkleStorage::put);
  147. merkleStorage.commit();
  148. System.out.printf("Batch %d completed in %d%n", batch, (System.currentTimeMillis()-batchStart));
  149. }
  150. System.out.printf("Job completed in %d%n", System.currentTimeMillis()-startTime);
  151. long compactTime = System.currentTimeMillis();
  152. db.compactRange();
  153. System.out.printf("Compaction time %d%n", System.currentTimeMillis()-compactTime);
  154.  
  155. }
  156. } catch (RocksDBException e) {
  157.  
  158. }
  159. }
  160. }
  161.  
  162.  
  163.  
  164.  
  165. File2;
  166.  
  167. package org.hyperledger.besu.ethereum.trie;
  168.  
  169.  
  170. import org.hyperledger.besu.plugin.services.exception.StorageException;
  171. import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
  172. import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;
  173. import org.rocksdb.RocksDB;
  174. import org.rocksdb.RocksDBException;
  175. import org.rocksdb.WriteBatch;
  176. import org.rocksdb.WriteOptions;
  177.  
  178. import java.io.IOException;
  179. import java.util.Optional;
  180. import java.util.Set;
  181. import java.util.function.Predicate;
  182. import java.util.stream.Stream;
  183.  
  184. public class BenchmarkRocksStorage implements KeyValueStorage {
  185.  
  186.  
  187. final RocksDB db;
  188.  
  189. public BenchmarkRocksStorage(final RocksDB db) {
  190. this.db = db;
  191. }
  192.  
  193. @Override
  194. public void clear() throws StorageException {
  195. }
  196.  
  197. @Override
  198. public boolean containsKey(final byte[] key) throws StorageException {
  199. try {
  200. return db.get(key) != null;
  201. } catch (RocksDBException e) {
  202. throw new StorageException(e);
  203. }
  204. }
  205.  
  206. @Override
  207. public Optional<byte[]> get(final byte[] key) throws StorageException {
  208. try {
  209. return Optional.ofNullable(db.get(key));
  210. } catch (RocksDBException e) {
  211. throw new StorageException(e);
  212. }
  213. }
  214.  
  215. @Override
  216. public Stream<byte[]> streamKeys() throws StorageException {
  217. return null;
  218. }
  219.  
  220. @Override
  221. public boolean tryDelete(final byte[] key) throws StorageException {
  222. try {
  223. db.delete(key);
  224. return true;
  225. } catch (RocksDBException e) {
  226. throw new StorageException(e);
  227. }
  228. }
  229.  
  230. @Override
  231. public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {
  232. return Set.of();
  233. }
  234.  
  235. @Override
  236. public KeyValueStorageTransaction startTransaction() throws StorageException {
  237. final WriteOptions writeOpt = new WriteOptions().setNoSlowdown(true);
  238. final WriteBatch batch = new WriteBatch();
  239. return new KeyValueStorageTransaction() {
  240. @Override
  241. public void put(final byte[] key,final byte[] value) {
  242. try {
  243. batch.put(key, value);
  244. }catch (RocksDBException e) {
  245. throw new RuntimeException(e);
  246. }
  247. }
  248.  
  249. @Override
  250. public void remove(final byte[] key) {
  251. try {
  252. batch.delete(key);
  253. }catch (RocksDBException e) {
  254. throw new RuntimeException(e);
  255. }
  256. }
  257.  
  258. @Override
  259. public void commit() throws StorageException {
  260. try {
  261. db.write(writeOpt, batch);
  262. }catch (RocksDBException e) {
  263. throw new RuntimeException(e);
  264. }
  265. }
  266.  
  267. @Override
  268. public void rollback() {
  269.  
  270. }
  271. };
  272. }
  273.  
  274. @Override
  275. public void close() throws IOException {
  276. db.close();
  277. }
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement