Skip to content

Instantly share code, notes, and snippets.

@cachenbach cachenbach/Benchmark.java Secret
Created Apr 28, 2019

Embed
What would you like to do?
import io.zeebe.client.ZeebeClient;
import io.zeebe.client.api.clients.JobClient;
import io.zeebe.client.api.response.ActivatedJob;
import io.zeebe.client.api.subscription.JobHandler;
import io.zeebe.client.api.subscription.JobWorker;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Benchmark {
public static void main(String[] args) throws InterruptedException {
List<JobWorker> jobWorkerList = new ArrayList<>();
List<ZeebeClient> zeebeClientList = new ArrayList<>();
for (int i = 0; i < 10; i++) {
ZeebeClient client = ZeebeClient.newClientBuilder().brokerContactPoint("localhost:26500").build();
zeebeClientList.add(client);
jobWorkerList.add(
client.newWorker()
.jobType("noop")
.handler(new NoOpbHandler())
.timeout(Duration.ofSeconds(100))
.open());
}
ExecutorService es = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
es.submit(new Runnable() {
@Override
public void run() {
try (ZeebeClient client2 = ZeebeClient.newClientBuilder().brokerContactPoint("localhost:26500").build()) {
for (int j = 0; j < 3000; j++) {
client2.newCreateInstanceCommand()
.bpmnProcessId("Process_1rqmvpl")
.latestVersion()
.send().join();
}
}
}
});
}
es.shutdown();
es.awaitTermination(10, TimeUnit.MINUTES);
jobWorkerList.forEach(w -> w.close());
zeebeClientList.forEach(c -> c.close());
}
private static class NoOpbHandler implements JobHandler {
@Override
public void handle(final JobClient client, final ActivatedJob job) {
client.newCompleteCommand(job.getKey()).send();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.