Search in sources :

Example 1 with ContractValue

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

the class EclipseMapBench method setup.

@Setup(Level.Trial)
public void setup() {
    nextIndex = numEntities;
    map = new LongObjectHashMap<ContractValue>().asSynchronized();
    // fill with some data
    for (long i = 0; i < numEntities; i++) {
        map.put(i, new ContractValue(i));
    }
    // print memory usage
    System.out.printf("Memory for initial %,d accounts:\n", numEntities);
    printMemoryUsage();
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) LongObjectHashMap(org.eclipse.collections.impl.map.mutable.primitive.LongObjectHashMap)

Example 2 with ContractValue

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

the class EclipseMapBench method add.

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

Example 3 with ContractValue

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

the class EclipseMapBench 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((long) random.nextInt(numEntities)));
            map.put((long) random.nextInt(numEntities), new ContractValue(random.nextLong()));
        }
    });
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom)

Example 4 with ContractValue

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

the class ContractBench method prepare.

@Setup
public void prepare() throws Exception {
    pipeline = new Pipeline<>();
    final long estimatedNumKeyValuePairs = (long) (numContracts * (1 - bigPercent - hugePercent) * ((kbPerContract * 1024L) / ESTIMATED_KEY_VALUE_SIZE)) + (long) (numContracts * bigPercent * ((kbPerBigContract * 1024L) / ESTIMATED_KEY_VALUE_SIZE)) + (long) (numContracts * hugePercent * ((kbPerHugeContract * 1024L) / ESTIMATED_KEY_VALUE_SIZE));
    System.out.println("estimatedNumKeyValuePairs = " + estimatedNumKeyValuePairs);
    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);
    Path dataSourcePath = getDataSourcePath(dsType);
    boolean dataSourceDirExisted = Files.exists(dataSourcePath);
    virtualMap = createMap(dsType, virtualLeafRecordSerializer, new ContractKeySerializer(), estimatedNumKeyValuePairs, dataSourcePath, preferDiskBasedIndexes);
    txProcessor = new TransactionProcessor<>(preFetchEventHandlers, (Transaction<Data> tx) -> {
        // preFetch logic
        VirtualMap<ContractKey, ContractValue> map = getVirtualMap();
        final Data data = tx.getData();
        data.value1 = map.getForModify(data.key1);
        data.value2 = map.getForModify(data.key2);
    }, (Transaction<Data> tx) -> {
        // handleTransaction logic
        final Data data = tx.getData();
        data.value1.setValue(data.value1.asLong() - data.transferAmount);
        data.value2.setValue(data.value2.asLong() + data.transferAmount);
    });
    // We generate a different number of key/value pairs depending on whether it is
    // a huge contract, big contract, or normal contract
    int numBigContracts = (int) (numContracts * bigPercent);
    System.out.println("numBigContracts = " + numBigContracts);
    int numHugeContracts = (int) (numContracts * hugePercent);
    System.out.println("numHugeContracts = " + numHugeContracts);
    keyValuePairsPerContract = new int[numContracts];
    for (int i = 0; i < numContracts; i++) {
        final int kb;
        if (i > 0 && (i % 100) == 0 && numHugeContracts > 0) {
            kb = kbPerHugeContract;
            numHugeContracts--;
        } else if (i > 0 && (i % 10) == 0 && numBigContracts > 0) {
            kb = kbPerBigContract;
            numBigContracts--;
        } else {
            kb = kbPerContract;
        }
        final var numKeyValuePairs = (kb * 1024L) / ESTIMATED_KEY_VALUE_SIZE;
        keyValuePairsPerContract[i] = (int) numKeyValuePairs;
    }
    if (!dataSourceDirExisted && preFill) {
        long countOfKeyValuePairs = 0;
        long lastCountOfKeyValuePairs = 0;
        for (int i = 0; i < numContracts; i++) {
            if ((countOfKeyValuePairs - lastCountOfKeyValuePairs) > 100_000) {
                lastCountOfKeyValuePairs = countOfKeyValuePairs;
                System.out.printf("Completed: %,d contracts and %,d key/value pairs\n", i, countOfKeyValuePairs);
                virtualMap = pipeline.endRound(virtualMap);
            }
            if (i > 0 && i % 10000 == 0) {
                System.out.println("=============== GC =======================");
                // loading is really intense so give GC a chance to catch up
                System.gc();
                Thread.sleep(1000);
            }
            final int numKeyValuePairs = keyValuePairsPerContract[i];
            for (int j = 0; j < numKeyValuePairs; j++) {
                final var key = asContractKey(i, j);
                final var value = new ContractValue(j);
                try {
                    virtualMap.put(key, value);
                } catch (Exception e) {
                    e.printStackTrace();
                    System.err.println(i + ":" + j);
                    throw e;
                }
            }
            countOfKeyValuePairs += numKeyValuePairs;
        }
        // During setup, we perform the full hashing and release the old copy. This way,
        // during the tests, we don't have an initial slow hash.
        System.out.printf("Completed: %,d contracts and %,d key/value pairs\n", numContracts, countOfKeyValuePairs);
        virtualMap = pipeline.endRound(virtualMap);
    } else {
        System.out.println("NOT PRE_FILLING AS LOADED FROM FILES OR TURNED OFF WITH FLAG!");
    }
    printDataStoreSize();
    // create a snapshot every 15min
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd--HH-mm");
    ScheduledExecutorService snapshotting = Executors.newScheduledThreadPool(1, runnable -> new Thread(runnable, "Snapshot"));
    snapshotting.scheduleWithFixedDelay(() -> {
        final Path snapshotDir = Path.of("jasperdb_snapshot_" + df.format(new Date()));
        System.out.println("************ STARTING SNAPSHOT [" + snapshotDir.toAbsolutePath() + "] ***********");
        long START = System.currentTimeMillis();
        try {
            virtualMap.getDataSource().snapshot(snapshotDir);
        } catch (IOException e) {
            e.printStackTrace();
        }
        double tookSeconds = (System.currentTimeMillis() - START) * Units.MILLISECONDS_TO_SECONDS;
        System.out.printf("************ SNAPSHOT FINISHED took %,3f seconds [%s] ***********\n", tookSeconds, snapshotDir.toAbsolutePath());
    }, 0, 5, TimeUnit.MINUTES);
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) ContractValueSupplier(com.hedera.services.state.virtual.ContractValueSupplier) ContractKeySupplier(com.hedera.services.state.virtual.ContractKeySupplier) Path(java.nio.file.Path) VFCMapBenchBase.getDataSourcePath(virtual.VFCMapBenchBase.getDataSourcePath) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) VirtualLeafRecordSerializer(com.swirlds.jasperdb.VirtualLeafRecordSerializer) IOException(java.io.IOException) IOException(java.io.IOException) Date(java.util.Date) VirtualMap(com.swirlds.virtualmap.VirtualMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ContractKeySerializer(com.hedera.services.state.virtual.ContractKeySerializer) SimpleDateFormat(java.text.SimpleDateFormat) Setup(org.openjdk.jmh.annotations.Setup)

Example 5 with ContractValue

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

the class UpdateBench method updateLeavesAndInternals.

@Benchmark
public void updateLeavesAndInternals(DatabaseMergingState databaseState) throws IOException {
    var internalRecordStream = IntStream.range(0, NUMBER_OF_INTERNALS_CHANGED_PER_FLUSH).mapToObj(i -> new VirtualInternalRecord(randomInternalPaths[i], hash((int) randomInternalPaths[i])));
    var leafRecordStream = IntStream.range(0, NUMBER_OF_LEAVES_CHANGED_PER_FLUSH).mapToObj(i -> {
        final long path = randomLeafPaths[i];
        return new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path, path), new ContractValue(path));
    });
    databaseState.dataSource.saveRecords(databaseState.dataSource.getFirstLeafPath(), databaseState.dataSource.getLastLeafPath(), internalRecordStream, leafRecordStream, Stream.empty());
}
Also used : ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) VirtualInternalRecord(com.swirlds.virtualmap.datasource.VirtualInternalRecord) Benchmark(org.openjdk.jmh.annotations.Benchmark)

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