https://github.com/scalecube/scalecube-benchmarks
Benchmarks framework
https://github.com/scalecube/scalecube-benchmarks
Last synced: 2 months ago
JSON representation
Benchmarks framework
- Host: GitHub
- URL: https://github.com/scalecube/scalecube-benchmarks
- Owner: scalecube
- License: apache-2.0
- Created: 2018-06-21T15:21:02.000Z (almost 7 years ago)
- Default Branch: develop
- Last Pushed: 2021-12-14T21:07:51.000Z (over 3 years ago)
- Last Synced: 2025-01-13T17:18:56.384Z (4 months ago)
- Language: Java
- Homepage:
- Size: 392 KB
- Stars: 3
- Watchers: 15
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scalecube-benchmarks
Benchmarks framework## Download
```xml
io.scalecube
scalecube-benchmarks-api
1.1.9```
## Getting started
First, you need to create the settings which will be used while test is running:
```java
public static void main(String[] args) {
BenchmarksSettings settings = BenchmarksSettings.from(args)
.nThreads(2)
.durationUnit(TimeUnit.NANOSECONDS)
.build();
....
}
```To override default settings with the command line include them as program variables at startup of the test. Or set them up programmatically inside a runner. See complete list of settings [here](https://github.com/scalecube/scalecube-benchmarks/wiki/Benchmarks-settings).
The second point is you need to prepare BenchmarksState instance for 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 reuse the same BenchmarksState class in different scenarios:
```java
public class ExampleServiceBenchmarksState extends BenchmarksState {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 class has a few necessary methods, about them below.### runForSync
```java
void runForSync(Function> func)
```This method intends for execution of synchronous tasks. As input you have to provide a function that should return the execution to be tested for the given the state at certain iteration. For instance:
```java
public static void main(String[] args) {
BenchmarksSettings settings = ...;
new RouterBenchmarksState(settings).runForSync(state -> {// prepare metrics, tools and etc. before actual test iterations start
Timer timer = state.timer("timer");
Router router = state.getRouter();// call and measure test scenario
return iteration -> {
Timer.Context timeContext = timer.time();
// NOTE: this call is synchronous
ServiceReference serviceReference = router.route(request);
timeContext.stop();
return serviceReference;
};
});
}
```### runForAsync
```java
void runForAsync(Function>> func)
```This method intends for execution of asynchronous tasks. It receives a function, that should return the execution to be tested for the given the state. Note, the unitOfwork (see `Function>` from the signature) should return some `Publisher`. For instance:
```java
public static void main(String[] args) {
BenchmarksSettings settings = ...;
new ExampleServiceBenchmarksState(settings).runForAsync(state -> {// prepare metrics before test interations start
ExampleService service = state.exampleService();
Meter meter = state.meter("meter");return iteration -> {
// NOTE: this is asynchronous call, method invoke retuns a publisher
return service.invoke("hello")
.doOnTerminate(() -> meter.mark());
};
});
}
```### runWithRampUp
```java
void runWithRampUp(BiFunction> setUp,
Function>> func,
BiFunction> cleanUp)
```This method intends for execution of asynchronous tasks with consumption some resources via ramp-up strategy. It receives three functions: setUp, unitOfWork, cleanUp.
First function `setUp` is a resource supplier; this function is being called on every ramp-up iteration.
The second function (see `BiFunction>`) is like unitOfWork supplier, actual test scenario must define here; this unitOfWork is being called on every test iteration and accepts as input a product of corresponding `setUp` call.
The third one is `cleanUp` supplier, that knows how to release resources that was created at ramp-up stage. More about ramp-up algorithm [here](https://github.com/scalecube/scalecube-benchmarks/wiki/Ramp-up-test-scenarios).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());
}
```