Search in sources :

Example 6 with ContractValue

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

the class CliffClickMapBench method putIfAbsent.

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

Example 7 with ContractValue

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

the class CliffClickMapBench method setup.

@Setup(Level.Trial)
public void setup() {
    nextIndex = numEntities;
    map = new NonBlockingHashMapLong<>(false);
    // fill with some data
    for (int 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)

Example 8 with ContractValue

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

the class ConcurrentMapBench 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 9 with ContractValue

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

the class ConcurrentMapBench method setup.

@Setup(Level.Trial)
public void setup() {
    nextIndex = numEntities;
    switch(impl) {
        case "SynchronizedHashMap":
            map = Collections.synchronizedMap(new HashMap<>());
            break;
        case "ConcurrentSkipListMap":
            map = new ConcurrentSkipListMap<>();
            break;
        default:
            map = new ConcurrentHashMap<>();
    }
    ;
    // 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) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 10 with ContractValue

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

the class ThorsFileHammer method updateAllValues.

public void updateAllValues() {
    try {
        final int batchSize = 1000;
        final int numOfBatches = (int) ((fileCollection.getMaximumValidKey() - fileCollection.getMinimumValidKey()) / batchSize);
        System.out.println("ThorsHammer.updateAllValues numOfBatches=" + numOfBatches);
        for (int batchIndex = 0; batchIndex < numOfBatches; batchIndex++) {
            final int firstLeaf = (int) (fileCollection.getMinimumValidKey() + (batchIndex * batchSize));
            final int lastLeaf = firstLeaf + batchSize;
            final var leafRecordStream = LongStream.range(firstLeaf, lastLeaf).mapToObj(path -> new VirtualLeafRecord<>(path, hash((int) path), new ContractKey(path / 1000, path), new ContractValue(RANDOM.nextLong()))).peek(leaf -> compareToMe.set((int) leaf.getPath(), (int) leaf.getValue().asLong()));
            try {
                readWriteLock.writeLock().lock();
                fileCollection.startWriting();
                final Map<Long, Long> indexUpdates = new HashMap<>();
                leafRecordStream.forEach(leaf -> {
                    try {
                        indexUpdates.put(leaf.getPath(), fileCollection.storeDataItem(leaf));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                final var dataFile = fileCollection.endWriting(fileCollection.getMinimumValidKey(), fileCollection.getMaximumValidKey());
                for (var update : indexUpdates.entrySet()) {
                    index.put(update.getKey(), update.getValue());
                }
                dataFile.setFileAvailableForMerging(true);
            } finally {
                readWriteLock.writeLock().unlock();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ContractValueSupplier(com.hedera.services.state.virtual.ContractValueSupplier) CommonTestUtils.hash(utils.CommonTestUtils.hash) LongStream(java.util.stream.LongStream) Files(java.nio.file.Files) ContractKey(com.hedera.services.state.virtual.ContractKey) ContractValue(com.hedera.services.state.virtual.ContractValue) CommonTestUtils.deleteDirectoryAndContents(utils.CommonTestUtils.deleteDirectoryAndContents) VirtualLeafRecordSerializer(com.swirlds.jasperdb.VirtualLeafRecordSerializer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataFileCommon(com.swirlds.jasperdb.files.DataFileCommon) IOException(java.io.IOException) HashMap(java.util.HashMap) Random(java.util.Random) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) DataFileCollection(com.swirlds.jasperdb.files.DataFileCollection) ContractKeySupplier(com.hedera.services.state.virtual.ContractKeySupplier) DigestType(com.swirlds.common.crypto.DigestType) Map(java.util.Map) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) LongListOffHeap(com.swirlds.jasperdb.collections.LongListOffHeap) Path(java.nio.file.Path) AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) ContractValue(com.hedera.services.state.virtual.ContractValue) ContractKey(com.hedera.services.state.virtual.ContractKey) HashMap(java.util.HashMap) VirtualLeafRecord(com.swirlds.virtualmap.datasource.VirtualLeafRecord) IOException(java.io.IOException)

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