Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The benchmark compares the Besu implementation (patriciaMerkleTrie+rocksdb) with PatriciaDB.
- The jobs inserts 40 batches of 100,000 key values (for a total of 4,000,000 keys).
- Each key/value is 32 bytes randomly generated.
- Besu: time 3'45", final database size after compaction: 2.1GB
- Batch 0 completed in 937
- Batch 1 completed in 1210
- Batch 2 completed in 1363
- Batch 3 completed in 1499
- Batch 4 completed in 1773
- Batch 5 completed in 1774
- Batch 6 completed in 2131
- Batch 7 completed in 2213
- Batch 8 completed in 2580
- Batch 9 completed in 2310
- Batch 10 completed in 2628
- Batch 11 completed in 2617
- Batch 12 completed in 2999
- Batch 13 completed in 3101
- Batch 14 completed in 3102
- Batch 15 completed in 3199
- Batch 16 completed in 4764
- Batch 17 completed in 4060
- Batch 18 completed in 3986
- Batch 19 completed in 3348
- Batch 20 completed in 3891
- Batch 21 completed in 3645
- Batch 22 completed in 5238
- Batch 23 completed in 10634
- Batch 24 completed in 9181
- Batch 25 completed in 6691
- Batch 26 completed in 6613
- Batch 27 completed in 5424
- Batch 28 completed in 13552
- Batch 29 completed in 9358
- Batch 30 completed in 8028
- Batch 31 completed in 6351
- Batch 32 completed in 6798
- Batch 33 completed in 12145
- Batch 34 completed in 10555
- Batch 35 completed in 9220
- Batch 36 completed in 9332
- Batch 37 completed in 14101
- Batch 38 completed in 10982
- Batch 39 completed in 10900
- Job completed in 224254
- Compaction time 12620
- PatriciaBD: 40 seconds, final database size (without compaction): 1.19GB
- Transaction 0 time 411
- Transaction 1 time 438
- Transaction 2 time 403
- Transaction 3 time 471
- Transaction 4 time 486
- Transaction 5 time 555
- Transaction 6 time 602
- Transaction 7 time 669
- Transaction 8 time 717
- Transaction 9 time 746
- Transaction 10 time 788
- Transaction 11 time 847
- Transaction 12 time 907
- Transaction 13 time 931
- Transaction 14 time 976
- Transaction 15 time 1028
- Transaction 16 time 1045
- Transaction 17 time 1075
- Transaction 18 time 1075
- Transaction 19 time 1095
- Transaction 20 time 1156
- Transaction 21 time 1173
- Transaction 22 time 1187
- Transaction 23 time 1190
- Transaction 24 time 1221
- Transaction 25 time 1241
- Transaction 26 time 1257
- Transaction 27 time 1289
- Transaction 28 time 1249
- Transaction 29 time 1228
- Transaction 30 time 1222
- Transaction 31 time 1237
- Transaction 32 time 1282
- Transaction 33 time 1275
- Transaction 34 time 1274
- Transaction 35 time 1353
- Transaction 36 time 1267
- Transaction 37 time 1263
- Transaction 38 time 1307
- Transaction 39 time 1257
- Total Time 40201
- Time: 40 seconds
- Follows the code use to run a benchmark on Basu.
- File1:
- package org.hyperledger.besu.ethereum.trie;
- import org.apache.tuweni.bytes.Bytes;
- import org.junit.jupiter.api.Test;
- import org.rocksdb.Options;
- import org.rocksdb.RocksDB;
- import org.rocksdb.RocksDBException;
- import java.util.Random;
- import java.util.function.Function;
- public class BesuPmtBenchmark {
- @Test
- public void runBenchmark() throws Exception{
- Random r= new Random(1);
- try (final Options options = new Options().setCreateIfMissing(true)) {
- try (final RocksDB db = RocksDB.open(options, "/Users/xavix/temp/benchmark/rocksdb")) {
- BenchmarkRocksStorage myRockKVStorage = new BenchmarkRocksStorage(db);
- var merkleStorage = new KeyValueMerkleStorage(myRockKVStorage);
- StoredMerklePatriciaTrie<Bytes, Bytes> s= new StoredMerklePatriciaTrie<>(merkleStorage::get, Function.identity(), Function.identity());
- var rootHash = s.getRootHash();
- s.commit(merkleStorage::put);
- byte[] key=new byte[32];
- byte[] value = new byte[32];
- long startTime = System.currentTimeMillis();
- for(int batch=0; batch< 40;batch++) {
- long batchStart = System.currentTimeMillis();
- StoredMerklePatriciaTrie<Bytes, Bytes> storage= new StoredMerklePatriciaTrie<>(merkleStorage::get,rootHash, Function.identity(), Function.identity());
- for(int i=0; i< 100_000; i++) {
- r.nextBytes(key);
- r.nextBytes(value);
- storage.put(Bytes.wrap(key), Bytes.wrap(value));
- }
- rootHash = storage.getRootHash();
- storage.commit(merkleStorage::put);
- merkleStorage.commit();
- System.out.printf("Batch %d completed in %d%n", batch, (System.currentTimeMillis()-batchStart));
- }
- System.out.printf("Job completed in %d%n", System.currentTimeMillis()-startTime);
- long compactTime = System.currentTimeMillis();
- db.compactRange();
- System.out.printf("Compaction time %d%n", System.currentTimeMillis()-compactTime);
- }
- } catch (RocksDBException e) {
- }
- }
- }
- File2;
- package org.hyperledger.besu.ethereum.trie;
- import org.hyperledger.besu.plugin.services.exception.StorageException;
- import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
- import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction;
- import org.rocksdb.RocksDB;
- import org.rocksdb.RocksDBException;
- import org.rocksdb.WriteBatch;
- import org.rocksdb.WriteOptions;
- import java.io.IOException;
- import java.util.Optional;
- import java.util.Set;
- import java.util.function.Predicate;
- import java.util.stream.Stream;
- public class BenchmarkRocksStorage implements KeyValueStorage {
- final RocksDB db;
- public BenchmarkRocksStorage(final RocksDB db) {
- this.db = db;
- }
- @Override
- public void clear() throws StorageException {
- }
- @Override
- public boolean containsKey(final byte[] key) throws StorageException {
- try {
- return db.get(key) != null;
- } catch (RocksDBException e) {
- throw new StorageException(e);
- }
- }
- @Override
- public Optional<byte[]> get(final byte[] key) throws StorageException {
- try {
- return Optional.ofNullable(db.get(key));
- } catch (RocksDBException e) {
- throw new StorageException(e);
- }
- }
- @Override
- public Stream<byte[]> streamKeys() throws StorageException {
- return null;
- }
- @Override
- public boolean tryDelete(final byte[] key) throws StorageException {
- try {
- db.delete(key);
- return true;
- } catch (RocksDBException e) {
- throw new StorageException(e);
- }
- }
- @Override
- public Set<byte[]> getAllKeysThat(final Predicate<byte[]> returnCondition) {
- return Set.of();
- }
- @Override
- public KeyValueStorageTransaction startTransaction() throws StorageException {
- final WriteOptions writeOpt = new WriteOptions().setNoSlowdown(true);
- final WriteBatch batch = new WriteBatch();
- return new KeyValueStorageTransaction() {
- @Override
- public void put(final byte[] key,final byte[] value) {
- try {
- batch.put(key, value);
- }catch (RocksDBException e) {
- throw new RuntimeException(e);
- }
- }
- @Override
- public void remove(final byte[] key) {
- try {
- batch.delete(key);
- }catch (RocksDBException e) {
- throw new RuntimeException(e);
- }
- }
- @Override
- public void commit() throws StorageException {
- try {
- db.write(writeOpt, batch);
- }catch (RocksDBException e) {
- throw new RuntimeException(e);
- }
- }
- @Override
- public void rollback() {
- }
- };
- }
- @Override
- public void close() throws IOException {
- db.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement