-
-
Save cachenbach/1ead4ef752a2c566bc1fbcede35e3927 to your computer and use it in GitHub Desktop.
This file contains 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
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