Search in sources :

Example 16 with ContractValue

use of com.hedera.services.state.virtual.ContractValue in project hedera-services by hashgraph.

the class VirtualDataSourceBench method b_add500Leaves.

@Benchmark
public void b_add500Leaves() throws IOException {
    final long firstLeafPath = dataSource.getFirstLeafPath();
    final long lastLeafPath = dataSource.getLastLeafPath();
    final long newFirstLeafPath = firstLeafPath + 500;
    final long newLastLeafPath = lastLeafPath + 1000;
    var internalRecordStream = LongStream.range(firstLeafPath, newFirstLeafPath).mapToObj(path -> new VirtualInternalRecord(path, hash((int) path)));
    var leafRecordStream = LongStream.range(lastLeafPath, newLastLeafPath + 1).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path)));
    dataSource.saveRecords(newFirstLeafPath, newLastLeafPath, internalRecordStream, leafRecordStream, Stream.empty());
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 17 with ContractValue

use of com.hedera.services.state.virtual.ContractValue in project hedera-services by hashgraph.

the class AddBench method add500Leaves.

@Benchmark
public void add500Leaves(DatabaseMergingState databaseState) throws IOException {
    final long firstLeafPath = databaseState.dataSource.getFirstLeafPath();
    final long lastLeafPath = databaseState.dataSource.getLastLeafPath();
    final long newFirstLeafPath = firstLeafPath + NUMBER_OF_LEAVES_ADDED_PER_FLUSH;
    final long newLastLeafPath = lastLeafPath + NUMBER_OF_LEAVES_ADDED_PER_FLUSH + NUMBER_OF_LEAVES_ADDED_PER_FLUSH;
    var internalRecordStream = LongStream.range(firstLeafPath, newFirstLeafPath).mapToObj(path -> new VirtualInternalRecord(path, hash((int) path)));
    var leafRecordStream = LongStream.range(lastLeafPath, newLastLeafPath + 1).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path)));
    databaseState.dataSource.saveRecords(newFirstLeafPath, newLastLeafPath, internalRecordStream, leafRecordStream, Stream.empty());
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 18 with ContractValue

use of com.hedera.services.state.virtual.ContractValue in project hedera-services by hashgraph.

the class DatabaseState method setupDatabase.

@Setup(Level.Trial)
public void setupDatabase() throws IOException {
    System.out.println("dataSourcePath = " + dataSourcePath + " mergingEnabled=" + mergingEnabled);
    if (Files.exists(dataSourcePath)) {
        System.err.println("!!!!!!!!!!!!! Deleting old db.");
        deleteDirectoryAndContents(dataSourcePath);
    }
    if (Files.exists(dataSourceSnapshotPath)) {
        System.err.println("!!!!!!!!!!!!! Deleting old db snapshot.");
        deleteDirectoryAndContents(dataSourceSnapshotPath);
    }
    // create data source
    VirtualLeafRecordSerializer<ContractKey, ContractValue> virtualLeafRecordSerializer = new VirtualLeafRecordSerializer<>((short) 1, DigestType.SHA_384, (short) 1, DataFileCommon.VARIABLE_DATA_SIZE, new ContractKeySupplier(), (short) 1, ContractValue.SERIALIZED_SIZE, new ContractValueSupplier(), true);
    JasperDbBuilder<ContractKey, ContractValue> dbBuilder = new JasperDbBuilder<>();
    dbBuilder.virtualLeafRecordSerializer(virtualLeafRecordSerializer).virtualInternalRecordSerializer(new VirtualInternalRecordSerializer()).keySerializer(new ContractKeySerializer()).storageDir(dataSourcePath).maxNumOfKeys(500_000_000).preferDiskBasedIndexes(false).internalHashesRamToDiskThreshold(0).mergingEnabled(mergingEnabled);
    dataSource = dbBuilder.build("jdb", "4dbState");
    // populate with initial data
    System.out.printf("Creating initial data set of %,d leaves\n", initialDataSize);
    progressPercentage = 0;
    final long firstLeafPath = initialDataSize;
    final long lastLeafPath = firstLeafPath + initialDataSize;
    var internalRecordStream = LongStream.range(0, firstLeafPath).mapToObj(path -> new VirtualInternalRecord(path, hash((int) path))).peek(internalRecord -> printProgress(internalRecord.getPath(), lastLeafPath));
    var leafRecordStream = LongStream.range(firstLeafPath, lastLeafPath + 1).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path))).peek(leaf -> printProgress(leaf.getPath(), lastLeafPath));
    dataSource.saveRecords(firstLeafPath, lastLeafPath, internalRecordStream, leafRecordStream, Stream.empty());
    System.out.printf("Done creating initial data set of %,d leaves\n", initialDataSize);
}
Also used : ContractValueSupplier(com.hedera.services.state.virtual.ContractValueSupplier) JasperDbBuilder(com.swirlds.jasperdb.JasperDbBuilder) ContractKey(com.hedera.services.state.virtual.ContractKey) VirtualInternalRecordSerializer(com.swirlds.jasperdb.VirtualInternalRecordSerializer) CommonTestUtils.deleteDirectoryAndContents(utils.CommonTestUtils.deleteDirectoryAndContents) VirtualLeafRecordSerializer(com.swirlds.jasperdb.VirtualLeafRecordSerializer) DataFileCommon(com.swirlds.jasperdb.files.DataFileCommon) Scope(org.openjdk.jmh.annotations.Scope) ContractKeySupplier(com.hedera.services.state.virtual.ContractKeySupplier) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) Path(java.nio.file.Path) CommonTestUtils.hash(utils.CommonTestUtils.hash) Setup(org.openjdk.jmh.annotations.Setup) LongStream(java.util.stream.LongStream) VirtualDataSourceJasperDB(com.swirlds.jasperdb.VirtualDataSourceJasperDB) Files(java.nio.file.Files) ContractValue(com.hedera.services.state.virtual.ContractValue) Param(org.openjdk.jmh.annotations.Param) IOException(java.io.IOException) State(org.openjdk.jmh.annotations.State) DigestType(com.swirlds.common.crypto.DigestType) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) Stream(java.util.stream.Stream) Level(org.openjdk.jmh.annotations.Level) ContractKeySerializer(com.hedera.services.state.virtual.ContractKeySerializer) VirtualLeafRecordSerializer(com.swirlds.jasperdb.VirtualLeafRecordSerializer) JasperDbBuilder(com.swirlds.jasperdb.JasperDbBuilder) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) ContractValueSupplier(com.hedera.services.state.virtual.ContractValueSupplier) VirtualInternalRecordSerializer(com.swirlds.jasperdb.VirtualInternalRecordSerializer) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) ContractKeySerializer(com.hedera.services.state.virtual.ContractKeySerializer) ContractKeySupplier(com.hedera.services.state.virtual.ContractKeySupplier) Setup(org.openjdk.jmh.annotations.Setup)

Example 19 with ContractValue

use of com.hedera.services.state.virtual.ContractValue in project hedera-services by hashgraph.

the class CliffClickMapBench method multiThreadedReadPut10kEach.

@Benchmark
public void multiThreadedReadPut10kEach(Blackhole blackHole) {
    IntStream.range(0, 5).parallel().forEach(jobID -> {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int i = 0; i < 2000; i++) {
            blackHole.consume(map.get(random.nextInt(numEntities)));
            map.put(random.nextInt(numEntities), new ContractValue(random.nextLong()));
        }
    });
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 20 with ContractValue

use of com.hedera.services.state.virtual.ContractValue in project hedera-services by hashgraph.

the class CliffClickMapBench method add.

@Benchmark
public void add() throws Exception {
    map.put(nextIndex, new ContractValue(nextIndex));
    nextIndex++;
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue)

Aggregations

ContractValue (com.hedera.services.state.virtual.ContractValue)23 ContractKey (com.hedera.services.state.virtual.ContractKey)13 ContractKeySupplier (com.hedera.services.state.virtual.ContractKeySupplier)8 ContractValueSupplier (com.hedera.services.state.virtual.ContractValueSupplier)8 VirtualLeafRecordSerializer (com.swirlds.jasperdb.VirtualLeafRecordSerializer)8 VirtualInternalRecord (com.swirlds.virtualmap.datasource.VirtualInternalRecord)8 Path (java.nio.file.Path)8 ContractKeySerializer (com.hedera.services.state.virtual.ContractKeySerializer)7 VirtualLeafRecord (com.swirlds.virtualmap.datasource.VirtualLeafRecord)7 IOException (java.io.IOException)7 DigestType (com.swirlds.common.crypto.DigestType)6 JasperDbBuilder (com.swirlds.jasperdb.JasperDbBuilder)6 VirtualInternalRecordSerializer (com.swirlds.jasperdb.VirtualInternalRecordSerializer)6 DataFileCommon (com.swirlds.jasperdb.files.DataFileCommon)6 Files (java.nio.file.Files)6 LongStream (java.util.stream.LongStream)6 VirtualDataSourceJasperDB (com.swirlds.jasperdb.VirtualDataSourceJasperDB)5 Random (java.util.Random)5 Stream (java.util.stream.Stream)5 Benchmark (org.openjdk.jmh.annotations.Benchmark)4