This repository was archived by the owner on Jun 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Updated readme #47
Merged
Merged
Updated readme #47
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,136 @@ | ||
# 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`). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elaborate more maybe about few of them. So far it is not clear what settings you are referring to.