Skip to content
This repository was archived by the owner on Jun 20, 2025. It is now read-only.

Feature/renamed annoying plural naming #86

Merged
merged 2 commits into from
Sep 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions benchmarks-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-benchmarks-parent</artifactId>
<version>1.1.16-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>

<artifactId>scalecube-benchmarks-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.scalecube.benchmarks;

import io.scalecube.benchmarks.metrics.BenchmarkMeter;
import io.scalecube.benchmarks.metrics.BenchmarkTimer;

public interface BenchmarkMetrics {

BenchmarkTimer timer(String name);

BenchmarkMeter meter(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.function.Predicate;
import java.util.regex.Pattern;

public class BenchmarksSettings {
public class BenchmarkSettings {

private static final int N_THREADS = Runtime.getRuntime().availableProcessors();
private static final int CONCURRENCY = 16;
Expand Down Expand Up @@ -64,7 +64,7 @@ public static Builder from(String[] args) {
return builder;
}

private BenchmarksSettings(Builder builder) {
private BenchmarkSettings(Builder builder) {
this.numberThreads = builder.numberThreads;
this.executionTaskDuration = builder.executionTaskDuration;
this.executionTaskInterval = builder.executionTaskInterval;
Expand Down Expand Up @@ -179,7 +179,7 @@ public int concurrency() {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("BenchmarksSettings{");
final StringBuilder sb = new StringBuilder("BenchmarkSettings{");
sb.append("numberThreads=").append(numberThreads);
sb.append(", concurrency=").append(concurrency);
sb.append(", executionTaskDuration=").append(executionTaskDuration);
Expand Down Expand Up @@ -328,8 +328,8 @@ public Builder concurrency(int concurrency) {
return this;
}

public BenchmarksSettings build() {
return new BenchmarksSettings(new Builder(this).parseArgs().calculateDynamicParams());
public BenchmarkSettings build() {
return new BenchmarkSettings(new Builder(this).parseArgs().calculateDynamicParams());
}

private Builder calculateDynamicParams() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.CsvReporter;
import com.codahale.metrics.MetricRegistry;
import io.scalecube.benchmarks.metrics.BenchmarksMeter;
import io.scalecube.benchmarks.metrics.BenchmarksTimer;
import io.scalecube.benchmarks.metrics.CodahaleBenchmarksMetrics;
import io.scalecube.benchmarks.metrics.BenchmarkMeter;
import io.scalecube.benchmarks.metrics.BenchmarkTimer;
import io.scalecube.benchmarks.metrics.CodahaleBenchmarkMetrics;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.CountDownLatch;
Expand All @@ -29,28 +29,28 @@
import reactor.core.scheduler.Schedulers;

/**
* BenchmarksState is the state of the benchmark. it gives you the analogy of the beginning, and
* BenchmarkState is the state of the benchmark. it gives you the analogy of the beginning, and
* ending of the test. It can run both sync or async way using the {@link #runForSync(Function)} and
* {@link #runForAsync(Function)} respectively.
*
* @param <S> when extending this class, please add your class as the S. ie.
* <pre>{@code
* public class ExampleBenchmarksState extends BenchmarksState<ExampleBenchmarksState> {
* public class ExampleBenchmarksState extends BenchmarkState<ExampleBenchmarksState> {
* ...
* }
* }</pre>
*/
public class BenchmarksState<S extends BenchmarksState<S>> {
public class BenchmarkState<S extends BenchmarkState<S>> {

private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarksState.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarkState.class);

protected final BenchmarksSettings settings;
protected final BenchmarkSettings settings;

private Scheduler scheduler;
private List<Scheduler> schedulers;

private MetricRegistry registry;
private BenchmarksMetrics metrics;
private BenchmarkMetrics metrics;

private ConsoleReporter consoleReporter;
private CsvReporter csvReporter;
Expand All @@ -60,7 +60,7 @@ public class BenchmarksState<S extends BenchmarksState<S>> {
private final AtomicBoolean warmUpOccurred = new AtomicBoolean(false);
private Disposable warmUpSubscriber;

public BenchmarksState(BenchmarksSettings settings) {
public BenchmarkState(BenchmarkSettings settings) {
this.settings = settings;
}

Expand All @@ -73,18 +73,18 @@ protected void afterAll() throws Exception {
}

/**
* Executes starting of the state, also it includes running of {@link BenchmarksState#beforeAll}.
* Executes starting of the state, also it includes running of {@link BenchmarkState#beforeAll}.
*/
public final void start() {
if (!started.compareAndSet(false, true)) {
throw new IllegalStateException("BenchmarksState is already started");
throw new IllegalStateException("BenchmarkState is already started");
}

LOGGER.info("Benchmarks settings: " + settings);

registry = new MetricRegistry();

metrics = new CodahaleBenchmarksMetrics(registry, warmUpOccurred::get);
metrics = new CodahaleBenchmarkMetrics(registry, warmUpOccurred::get);

if (settings.consoleReporterEnabled()) {
consoleReporter =
Expand Down Expand Up @@ -112,7 +112,7 @@ public final void start() {
try {
beforeAll();
} catch (Exception ex) {
throw new IllegalStateException("BenchmarksState beforeAll() failed: " + ex, ex);
throw new IllegalStateException("BenchmarkState beforeAll() failed: " + ex, ex);
}

Runtime.getRuntime()
Expand Down Expand Up @@ -143,11 +143,11 @@ public final void start() {

/**
* Executes shutdown process of the state, also it includes running of {@link
* BenchmarksState#afterAll}.
* BenchmarkState#afterAll}.
*/
public final void shutdown() {
if (!started.compareAndSet(true, false)) {
throw new IllegalStateException("BenchmarksState is not started");
throw new IllegalStateException("BenchmarkState is not started");
}

if (warmUpSubscriber != null) {
Expand Down Expand Up @@ -175,7 +175,7 @@ public final void shutdown() {
try {
afterAll();
} catch (Exception ex) {
throw new IllegalStateException("BenchmarksState afterAll() failed: " + ex, ex);
throw new IllegalStateException("BenchmarkState afterAll() failed: " + ex, ex);
}
}

Expand All @@ -197,7 +197,7 @@ public MetricRegistry registry() {
* @param name name
* @return timer with specified name
*/
public BenchmarksTimer timer(String name) {
public BenchmarkTimer timer(String name) {
return metrics.timer(settings.taskName() + "-" + name);
}

Expand All @@ -207,13 +207,13 @@ public BenchmarksTimer timer(String name) {
* @param name name
* @return meter with specified name
*/
public BenchmarksMeter meter(String name) {
public BenchmarkMeter meter(String name) {
return metrics.meter(settings.taskName() + "-" + name);
}

/**
* Runs given function in the state. It also executes {@link BenchmarksState#start()} before and
* {@link BenchmarksState#shutdown()} after.
* Runs given function in the state. It also executes {@link BenchmarkState#start()} before and
* {@link BenchmarkState#shutdown()} after.
*
* <p>NOTICE: It's only for synchronous code.
*
Expand Down Expand Up @@ -248,8 +248,8 @@ public final void runForSync(Function<S, Function<Long, Object>> func) {
}

/**
* Runs given function on this state. It also executes {@link BenchmarksState#start()} before and
* {@link BenchmarksState#shutdown()} after.
* Runs given function on this state. It also executes {@link BenchmarkState#start()} before and
* {@link BenchmarkState#shutdown()} after.
*
* <p>NOTICE: It's only for asynchronous code.
*
Expand Down Expand Up @@ -294,8 +294,8 @@ public final void runForAsync(Function<S, Function<Long, Publisher<?>>> func) {
* invoked with given intervals, according to the benchmark rampUp settings. And when the resource
* will be available then it will start executing the unitOfWork. And when execution of the
* unitOfWorks will be finished (by time completion or by iteration's completion) the resource
* will be released with the cleanUp function. It also executes {@link BenchmarksState#start()}
* before and {@link BenchmarksState#shutdown()} after.
* will be released with the cleanUp function. It also executes {@link BenchmarkState#start()}
* before and {@link BenchmarkState#shutdown()} after.
*
* @param setUp a function that should return some T type which one will be passed into next to
* the argument. Also, this function will be invoked with some ramp-up strategy, and when it
Expand Down Expand Up @@ -356,10 +356,10 @@ public final <T> void runWithRampUp(
.subscribeOn(scheduler)
.map(
setUpResult ->
new BenchmarksTask<>(
new BenchmarkTask<>(
self, setUpResult, unitOfWork, cleanUp, scheduler))
.doOnNext(scheduler::schedule)
.flatMap(BenchmarksTask::completionMono);
.flatMap(BenchmarkTask::completionMono);
});
},
Integer.MAX_VALUE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.scalecube.benchmarks;

import static io.scalecube.benchmarks.BenchmarksTask.Status.COMPLETED;
import static io.scalecube.benchmarks.BenchmarksTask.Status.COMPLETING;
import static io.scalecube.benchmarks.BenchmarksTask.Status.SCHEDULED;
import static io.scalecube.benchmarks.BenchmarkTask.Status.COMPLETED;
import static io.scalecube.benchmarks.BenchmarkTask.Status.COMPLETING;
import static io.scalecube.benchmarks.BenchmarkTask.Status.SCHEDULED;

import java.time.Duration;
import java.util.concurrent.CompletableFuture;
Expand All @@ -18,9 +18,9 @@
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;

public class BenchmarksTask<S extends BenchmarksState<S>, T> implements Runnable {
public class BenchmarkTask<S extends BenchmarkState<S>, T> implements Runnable {

private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarksTask.class);
private static final Logger LOGGER = LoggerFactory.getLogger(BenchmarkTask.class);

public enum Status {
SCHEDULED,
Expand Down Expand Up @@ -50,7 +50,7 @@ public enum Status {
* @param cleanUp a function that should clean up some T's resources.
* @param scheduler a scheduler.
*/
public BenchmarksTask(
public BenchmarkTask(
S benchmarksState,
T setUpResult,
BiFunction<Long, T, Publisher<?>> unitOfWork,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.scalecube.benchmarks.metrics;

public interface BenchmarksMeter {
public interface BenchmarkMeter {

void mark();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.concurrent.TimeUnit;

public interface BenchmarksTimer {
public interface BenchmarkTimer {

Context NO_OP_CONTEXT =
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
import com.codahale.metrics.Meter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import io.scalecube.benchmarks.BenchmarksMetrics;
import io.scalecube.benchmarks.BenchmarkMetrics;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

public class CodahaleBenchmarksMetrics implements BenchmarksMetrics {
public class CodahaleBenchmarkMetrics implements BenchmarkMetrics {

private final MetricRegistry registry;
private final Supplier<Boolean> enabled;

public CodahaleBenchmarksMetrics(MetricRegistry registry, Supplier<Boolean> enabled) {
public CodahaleBenchmarkMetrics(MetricRegistry registry, Supplier<Boolean> enabled) {
this.registry = registry;
this.enabled = enabled;
}

@Override
public BenchmarksTimer timer(String name) {
public BenchmarkTimer timer(String name) {
Timer timer = registry.timer(name);
return new BenchmarksTimer() {
return new BenchmarkTimer() {
@Override
public void update(long value, TimeUnit timeUnit) {
if (enabled.get()) {
Expand All @@ -47,9 +47,9 @@ public Context time() {
* @return meter with specified name
*/
@Override
public BenchmarksMeter meter(String name) {
public BenchmarkMeter meter(String name) {
Meter meter = registry.meter(name);
return new BenchmarksMeter() {
return new BenchmarkMeter() {
@Override
public void mark() {
meter.mark();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import java.time.Duration;
import org.junit.jupiter.api.Test;

class BenchmarksSettingsTest {
class BenchmarkSettingsTest {
private static final String[] EMPTY_ARGS = new String[] {};

@Test
void testOneUserAndSevenMsgRate() {
BenchmarksSettings settings =
BenchmarksSettings.from(EMPTY_ARGS)
BenchmarkSettings settings =
BenchmarkSettings.from(EMPTY_ARGS)
.injectors(1)
.messageRate(7)
.executionTaskDuration(Duration.ofSeconds(10))
Expand All @@ -32,8 +32,8 @@ void testInjectorsCount() {
int injectors = 1000;

// When
BenchmarksSettings settings =
BenchmarksSettings.from(EMPTY_ARGS)
BenchmarkSettings settings =
BenchmarkSettings.from(EMPTY_ARGS)
.injectors(injectors)
.rampUpDuration(Duration.ofSeconds(20))
.messageRate(10_000)
Expand Down
6 changes: 4 additions & 2 deletions benchmarks-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-benchmarks-parent</artifactId>
<version>1.1.16-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
</parent>

<artifactId>scalecube-benchmarks-examples</artifactId>
Expand Down
Loading