All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.swirlds.common.test.benchmark.BenchmarkConfiguration Maven / Gradle / Ivy

/*
 * Copyright (C) 2021-2023 Hedera Hashgraph, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.swirlds.common.test.benchmark;

import com.swirlds.common.merkle.MerkleNode;
import java.time.Duration;
import java.util.List;

/**
 * This class is used to configure and build a Benchmark object.
 *
 * @param 
 * 		the type of the merkle node state
 * @param 
 * 		the type of the benchmark state
 */
public class BenchmarkConfiguration {

    private M initialState;
    private B initialBenchmarkState;
    private List> mutableStateOperations;
    private List> immutableStateOperations;
    private int immutableThreadCount;
    private Duration roundPeriod;
    private int statesInMemory;
    private Duration spinUpTime;
    private Duration testDuration;

    public BenchmarkConfiguration() {
        immutableThreadCount = 5;
        roundPeriod = Duration.ofMillis(100);
        statesInMemory = 10;
        spinUpTime = Duration.ofSeconds(5);
        testDuration = Duration.ofMinutes(1);
    }

    /**
     * Build a new benchmark.
     */
    public Benchmark build() {
        final Benchmark benchmark = new Benchmark(
                initialState,
                initialBenchmarkState,
                mutableStateOperations,
                immutableStateOperations,
                immutableThreadCount,
                roundPeriod,
                statesInMemory,
                spinUpTime,
                testDuration);

        // These are modified by the benchmark, we must set them again if the configuration object is reused
        initialState = null;
        initialBenchmarkState = null;

        return benchmark;
    }

    /**
     * Get the initial merkle state.
     */
    public MerkleNode getInitialState() {
        return initialState;
    }

    /**
     * Set the initial merkle state.
     *
     * @return this object
     */
    public BenchmarkConfiguration setInitialState(final M initialState) {
        this.initialState = initialState;
        return this;
    }

    /**
     * Get the initial non-merkle state for the benchmark.
     */
    public B getInitialBenchmarkState() {
        return initialBenchmarkState;
    }

    /**
     * Set the initial non-merkle state for the benchmark.
     *
     * @return this object
     */
    public BenchmarkConfiguration setBenchmarkMetadata(final B initialBenchmarkState) {
        this.initialBenchmarkState = initialBenchmarkState;
        return this;
    }

    /**
     * Get the operations to perform on the mutable state.
     */
    public List> getMutableStateOperations() {
        return mutableStateOperations;
    }

    /**
     * Set the operations to perform on the mutable state.
     *
     * @return this object
     */
    public BenchmarkConfiguration setMutableStateOperations(
            final List> mutableStateOperations) {
        this.mutableStateOperations = mutableStateOperations;
        return this;
    }

    /**
     * Get the operations to perform on the immutable state copies.
     */
    public List> getImmutableStateOperations() {
        return immutableStateOperations;
    }

    /**
     * Set the operations to perform on the immutable state copies.
     *
     * @return this object
     */
    public BenchmarkConfiguration setImmutableStateOperations(
            final List> immutableStateOperations) {
        this.immutableStateOperations = immutableStateOperations;
        return this;
    }

    /**
     * Get the number of threads that will be running operations on immutable state copies.
     */
    public int getImmutableThreadCount() {
        return immutableThreadCount;
    }

    /**
     * Set the number of threads that will be running operations on immutable state copies.
     *
     * @return this object
     */
    public BenchmarkConfiguration setImmutableThreadCount(final int immutableThreadCount) {
        this.immutableThreadCount = immutableThreadCount;
        return this;
    }

    /**
     * Get the time between copies of the state.
     */
    public Duration getRoundPeriod() {
        return roundPeriod;
    }

    /**
     * Set the time between copies of the state.
     *
     * @return this object
     */
    public BenchmarkConfiguration setRoundPeriod(final Duration roundPeriod) {
        this.roundPeriod = roundPeriod;
        return this;
    }

    /**
     * Get the number of states that are kept in memory (excluding the mutable state).
     */
    public int getStatesInMemory() {
        return statesInMemory;
    }

    /**
     * Set the number of states that are kept in memory (excluding the mutable state).
     *
     * @return this object
     */
    public BenchmarkConfiguration setStatesInMemory(final int statesInMemory) {
        this.statesInMemory = statesInMemory;
        return this;
    }

    /**
     * Get the time to wait before starting the collection of statistics.
     */
    public Duration getSpinUpTime() {
        return spinUpTime;
    }

    /**
     * Set the time to wait before starting the collection of statistics.
     *
     * @return this object
     */
    public BenchmarkConfiguration setSpinUpTime(final Duration spinUpTime) {
        this.spinUpTime = spinUpTime;
        return this;
    }

    /**
     * Get the length of the test.
     */
    public Duration getTestDuration() {
        return testDuration;
    }

    /**
     * Set the length of the test.
     *
     * @return this object
     */
    public BenchmarkConfiguration setTestDuration(final Duration testDuration) {
        this.testDuration = testDuration;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy