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

Prepare new release #51

Merged
merged 24 commits into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
288466d
++++ Prepare for next development iteration build: 233 ++++
io-scalecube-ci Jul 17, 2018
f32c016
Updated readme
segabriel Jul 17, 2018
29014e3
Fixed some typo
segabriel Jul 17, 2018
ad065a6
Fixed typo
segabriel Jul 17, 2018
8258272
Improved sync/async benchmarks
segabriel Jul 17, 2018
ccfc8f2
Added syntax highlighting
segabriel Jul 17, 2018
2577ebd
Fixed checkstyle
segabriel Jul 17, 2018
8a63cb5
Update README.md
segabriel Jul 18, 2018
d60ae2a
Minor
segabriel Jul 18, 2018
7553055
Added alias support for creating main directory
segabriel Jul 18, 2018
5493899
Reverted changes for async method
segabriel Jul 18, 2018
334fffa
Merge pull request #47 from scalecube/feature/update-readme
artem-v Jul 18, 2018
6e85c68
Merge branch 'develop' into feature/improve-benchmarks
artem-v Jul 18, 2018
a27e787
Merge branch 'develop' into feature/add-alias-support
artem-v Jul 18, 2018
fb35b7c
Merge pull request #49 from scalecube/feature/add-alias-support
artem-v Jul 18, 2018
e28ed29
Merge branch 'develop' into feature/improve-benchmarks
artem-v Jul 18, 2018
604cb97
Merge pull request #48 from scalecube/feature/improve-benchmarks
artem-v Jul 18, 2018
35f6895
Improved logging, split by benchmark tests
segabriel Jul 20, 2018
be2180e
Added opportunity change logLevel via environment variable
segabriel Jul 20, 2018
1d1887b
Minor
segabriel Jul 20, 2018
9543969
Minor improvements
segabriel Jul 20, 2018
2d3d55e
Update README.md
segabriel Jul 20, 2018
98ace83
Merge pull request #50 from scalecube/feature/improve-logging
artem-v Jul 20, 2018
b93b092
Merge branch 'master' into develop
artem-v Jul 20, 2018
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
/reports
*/reports
*.csv
*.log
*.zip

# Mac-specific directory that no other operating system needs.
.DS_Store
Expand Down
137 changes: 137 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,139 @@
# scalecube-benchmarks
Microbenchmarks framework

## Download

```xml
<dependency>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-benchmarks-api</artifactId>
<version>1.1.8</version>
</dependency>
```

## Getting started

First, you need to create the settings which will be used while test is running. You can use the builder for it:

```java
public static void main(String[] args) {
BenchmarksSettings settings = BenchmarksSettings.from(args)
.nThreads(2)
.durationUnit(TimeUnit.NANOSECONDS)
.build();
....
}
```

As you see, you could want to override some default settings with the command line, just include them during startup of the test. Or just use the hardcoded style when you write a test scenario.

The second point is you need to prepare some state for your test scenario. You can define how to launch your server, launch some client or just execute some work before running test scenario. For instance, you can create a separated class to reduce writing your scenario in a test or reuse the same state in different scenarios.

```java
public class ExampleServiceBenchmarksState extends BenchmarksState<ExampleServiceBenchmarksState> {

private ExampleService exampleService;

public ExampleServiceBenchmarksState(BenchmarksSettings settings) {
super(settings);
}

@Override
public void beforeAll() {
this.exampleService = new ExampleService();
}

public ExampleService exampleService() {
return exampleService;
}
}
```
You can override two methods: `beforeAll` and `afterAll`, these methods will be invoked before test execution and after test termination. The state also may need some settings and it can get them from given BenchmarkSettings via constructor. Also, this state has a few necessary methods, about them below.

### runForSync

```java
void runForSync(Function<SELF, Function<Long, Object>> func)
```

This method intends for execution synchronous tasks. It receives a function, that should return the execution to be tested for the given the state. For instance:

```java
public static void main(String[] args) {
BenchmarksSettings settings = ...;
new RouterBenchmarksState(settings).runForSync(state -> {

Timer timer = state.timer("timer");
Router router = state.getRouter();

return iteration -> {
Timer.Context timeContext = timer.time();
ServiceReference serviceReference = router.route(request);
timeContext.stop();
return serviceReference;
};
});
}
```

As you see, to use this method you need return some function, to generate one you can use the transferred state and iteration's number.

### runForAsync

```java
void runForAsync(Function<SELF, Function<Long, Publisher<?>>> func)
```

This method intends for execution asynchronous tasks. It receives a function, that should return the execution to be tested for the given the state. Note, the unitOfwork should return some `Publisher`. For instance:

```java
public static void main(String[] args) {
BenchmarksSettings settings = ...;
new ExampleServiceBenchmarksState(settings).runForAsync(state -> {

ExampleService service = state.exampleService();
Meter meter = state.meter("meter");

return iteration -> {
return service.invoke("hello")
.doOnTerminate(() -> meter.mark());
};
});
}
```

As you see, to use this method you need return some function, to generate one you can use the transferred state and iteration's number.

### runWithRampUp

```java
<T> void runWithRampUp(BiFunction<Long, SELF, Publisher<T>> setUp,
Function<SELF, BiFunction<Long, T, Publisher<?>>> func,
BiFunction<SELF, T, Mono<Void>> cleanUp)
```

This method intends for execution asynchronous tasks with consumption some resources via ramp-up strategy. It receives three functions, they are necessary to provide all resource life-cycle. The first function is like resource supplier, to implement this one you have access to the active state and a ramp-up iteration's number. And when ramp-up strategy asks for new resources it will be invoked. The second function is like unitOfWork supplier, to implement this one you receive the active state (to take some services or metric's tools), iteration's number and a resource, that was created on the former step. And the last function is like clean-up supplier, that knows how to need release given resource. For instance:

```java
public static void main(String[] args) {
BenchmarksSettings settings = BenchmarksSettings.from(args)
.rampUpDuration(Duration.ofSeconds(10))
.rampUpInterval(Duration.ofSeconds(1))
.executionTaskDuration(Duration.ofSeconds(30))
.executionTaskInterval(Duration.ofMillis(100))
.build();

new ExampleServiceBenchmarksState(settings).runWithRampUp(
(rampUpIteration, state) -> Mono.just(new ServiceCaller(state.exampleService()),
state -> {
Meter meter = state.meter("meter");
return (iteration, serviceCaller) -> serviceCaller.call("hello").doOnTerminate(meter::mark);
},
(state, serviceCaller) -> serviceCaller.close());
}
```

It's time to describe the settings in more detail. First, you can see two ramp-up parameters, these are `rampUpDuration` and `rampUpInterval`. They need to specify how long will be processing ramp-up stage and how often will be invoked the resource supplier to receive a new resource. Also, we have two parameters to specify how long will be processing all `unitOfWork`s on the given resource (`executionTaskDuration`) and with another one you can specify some interval that will be applied to invoke the next `unitOfWork` on the given resource (`executionTaskInterval`).

## Additional links
+ [How-to-launch-benchmarks](https://github.com/scalecube/scalecube-benchmarks/wiki/How-to-launch-benchmarks)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

public class BenchmarksSettings {
Expand All @@ -25,6 +24,7 @@ public class BenchmarksSettings {
private static final long NUM_OF_ITERATIONS = Long.MAX_VALUE;
private static final Duration RAMP_UP_DURATION = Duration.ofSeconds(10);
private static final Duration RAMP_UP_INTERVAL = Duration.ofSeconds(1);
private static final boolean CONSOLE_REPORTER_ENABLED = true;

private final int nThreads;
private final Duration executionTaskDuration;
Expand All @@ -38,6 +38,7 @@ public class BenchmarksSettings {
private final long numOfIterations;
private final Duration rampUpDuration;
private final Duration rampUpInterval;
private final boolean consoleReporterEnabled;

private final Map<String, String> options;

Expand All @@ -51,23 +52,21 @@ private BenchmarksSettings(Builder builder) {
this.executionTaskInterval = builder.executionTaskInterval;
this.reporterInterval = builder.reporterInterval;
this.numOfIterations = builder.numOfIterations;

this.consoleReporterEnabled = builder.consoleReporterEnabled;
this.rampUpDuration = builder.rampUpDuration;
this.rampUpInterval = builder.rampUpInterval;

this.options = builder.options;

this.registry = new MetricRegistry();

this.durationUnit = builder.durationUnit;
this.rateUnit = builder.rateUnit;

this.registry = new MetricRegistry();

StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
this.taskName = minifyClassName(stackTrace[stackTrace.length - 1].getClassName());

String time = LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"));
this.csvReporterDirectory = Paths.get("benchmarks", "results", taskName + allPropertiesAsString(), time).toFile();
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss"));
this.csvReporterDirectory = Paths.get("benchmarks", "results", find("alias", taskName), time).toFile();
// noinspection ResultOfMethodCallIgnored
this.csvReporterDirectory.mkdirs();
}
Expand Down Expand Up @@ -124,6 +123,10 @@ public Duration rampUpInterval() {
return rampUpInterval;
}

public boolean consoleReporterEnabled() {
return consoleReporterEnabled;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("BenchmarksSettings{");
Expand All @@ -138,6 +141,7 @@ public String toString() {
sb.append(", rateUnit=").append(rateUnit);
sb.append(", rampUpDuration=").append(rampUpDuration);
sb.append(", rampUpInterval=").append(rampUpInterval);
sb.append(", consoleReporterEnabled=").append(consoleReporterEnabled);
sb.append(", registry=").append(registry);
sb.append(", options=").append(options);
sb.append('}');
Expand All @@ -148,21 +152,6 @@ private String minifyClassName(String className) {
return className.replaceAll("\\B\\w+(\\.[a-zA-Z])", "$1");
}

private String allPropertiesAsString() {
Map<String, String> allProperties = new TreeMap<>(options);
allProperties.put("nThreads", String.valueOf(nThreads));
allProperties.put("executionTaskDuration", String.valueOf(executionTaskDuration));
allProperties.put("executionTaskInterval", String.valueOf(executionTaskInterval));
allProperties.put("numOfIterations", String.valueOf(numOfIterations));
allProperties.put("rampUpDuration", String.valueOf(rampUpDuration));
allProperties.put("rampUpInterval", String.valueOf(rampUpInterval));
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : allProperties.entrySet()) {
sb.append("_").append(entry.getKey()).append("=").append(entry.getValue());
}
return sb.toString();
}

public static class Builder {
private final Map<String, String> options = new HashMap<>();

Expand All @@ -175,6 +164,7 @@ public static class Builder {
private long numOfIterations = NUM_OF_ITERATIONS;
private Duration rampUpDuration = RAMP_UP_DURATION;
private Duration rampUpInterval = RAMP_UP_INTERVAL;
private boolean consoleReporterEnabled = CONSOLE_REPORTER_ENABLED;

public Builder from(String[] args) {
this.parse(args);
Expand Down Expand Up @@ -233,6 +223,11 @@ public Builder rampUpInterval(Duration rampUpInterval) {
return this;
}

public Builder consoleReporterEnabled(boolean consoleReporterEnabled) {
this.consoleReporterEnabled = consoleReporterEnabled;
return this;
}

public BenchmarksSettings build() {
return new BenchmarksSettings(this);
}
Expand Down Expand Up @@ -265,6 +260,9 @@ private void parse(String[] args) {
case "rampUpIntervalInMillis":
rampUpInterval(Duration.ofMillis(Long.parseLong(value)));
break;
case "consoleReporterEnabled":
consoleReporterEnabled(Boolean.parseBoolean(value));
break;
default:
addOption(key, value);
break;
Expand Down
Loading