Skip to content

Use a virtual thread factory #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
74 changes: 35 additions & 39 deletions src/main/java/io/fusionauth/load/Foreman.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2022, FusionAuth, All Rights Reserved
* Copyright (c) 2012-2025, FusionAuth, All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,55 +47,51 @@ public class Foreman implements Buildable<Foreman> {

public Foreman execute() throws InterruptedException {
initialize();
ExecutorService pool = Executors.newFixedThreadPool(workers.size());

// Gradually build up workers, to reduce the chance of failures while we get going.
for (Worker worker : workers) {
WorkerExecutor executor = new WorkerExecutor(worker, loopCount, listeners);
pool.execute(executor);
try {
Thread.sleep(1123);
} catch (Exception ignore) {
try (ExecutorService pool = Executors.newVirtualThreadPerTaskExecutor()) {

// Gradually build up workers, to reduce the chance of failures while we get going.
for (Worker worker : workers) {
WorkerExecutor executor = new WorkerExecutor(worker, loopCount, listeners);
pool.execute(executor);
}
}

if (this.reporter != null) {
this.reporter.schedule();
}
if (this.reporter != null) {
this.reporter.schedule();
}

pool.shutdown();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
pool.shutdown();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);

listeners.forEach(SampleListener::done);
listeners.forEach(SampleListener::done);

if (reporter != null) {
reporter.report();
}
if (reporter != null) {
reporter.report();
}

if (reporter != null) {
reporter.stop();
}
if (reporter != null) {
reporter.stop();
}

// Temp hack to get some general timings on the OAuth2 Authorize worker broken down by component
if (workers.get(0) instanceof FusionAuthOAuth2AuthorizeWorker) {
System.out.println("\n\n");
long total = FusionAuthOAuth2AuthorizeWorker.timing.render + FusionAuthOAuth2AuthorizeWorker.timing.post + FusionAuthOAuth2AuthorizeWorker.timing.token;
long iterationCount = (long) workers.size() * loopCount;

// Temp hack to get some general timings on the OAuth2 Authorize worker broken down by component
if (workers.get(0) instanceof FusionAuthOAuth2AuthorizeWorker) {
System.out.println("\n\n");
long total = FusionAuthOAuth2AuthorizeWorker.timing.render + FusionAuthOAuth2AuthorizeWorker.timing.post + FusionAuthOAuth2AuthorizeWorker.timing.token;
long iterationCount = (long) workers.size() * loopCount;
int renderPercent = (int) (FusionAuthOAuth2AuthorizeWorker.timing.render * 100.0 / total + 0.5);
int postPercent = (int) (FusionAuthOAuth2AuthorizeWorker.timing.post * 100.0 / total + 0.5);
int tokenPercent = (int) (FusionAuthOAuth2AuthorizeWorker.timing.token * 100.0 / total + 0.5);

int renderPercent = (int) (FusionAuthOAuth2AuthorizeWorker.timing.render * 100.0 / total + 0.5);
int postPercent = (int) (FusionAuthOAuth2AuthorizeWorker.timing.post * 100.0 / total + 0.5);
int tokenPercent = (int) (FusionAuthOAuth2AuthorizeWorker.timing.token * 100.0 / total + 0.5);
System.out.println("Render: " + FusionAuthOAuth2AuthorizeWorker.timing.render + " ms, Average: " + FusionAuthOAuth2AuthorizeWorker.timing.render / (iterationCount) + " ms, " + (renderPercent) + "%");
System.out.println("Post: " + FusionAuthOAuth2AuthorizeWorker.timing.post + " ms, Average: " + FusionAuthOAuth2AuthorizeWorker.timing.post / (iterationCount) + " ms, " + (postPercent) + "%");
System.out.println("Token: " + FusionAuthOAuth2AuthorizeWorker.timing.token + " ms, Average: " + FusionAuthOAuth2AuthorizeWorker.timing.token / (iterationCount) + " ms, " + (tokenPercent) + "%");
System.out.println("\n\n");
}

System.out.println("Render: " + FusionAuthOAuth2AuthorizeWorker.timing.render + " ms, Average: " + FusionAuthOAuth2AuthorizeWorker.timing.render / (iterationCount) + " ms, " + (renderPercent) + "%");
System.out.println("Post: " + FusionAuthOAuth2AuthorizeWorker.timing.post + " ms, Average: " + FusionAuthOAuth2AuthorizeWorker.timing.post / (iterationCount) + " ms, " + (postPercent) + "%");
System.out.println("Token: " + FusionAuthOAuth2AuthorizeWorker.timing.token + " ms, Average: " + FusionAuthOAuth2AuthorizeWorker.timing.token / (iterationCount) + " ms, " + (tokenPercent) + "%");
System.out.println("\n\n");
done = true;
initialized = true;
return this;
}

done = true;
initialized = true;
return this;
}

public void initialize() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/Create-Applications.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 100,
"workerCount": 20,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/Create-Tenants.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 100,
"workerCount": 20,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/HTTP.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 500000,
"workerCount": 20,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.HTTPWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/OAuth2-AuthorizationCodeGrant.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 100,
"workerCount": 20,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/User-Logins.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 1000,
"workerCount": 50,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/User-Registrations.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 1000,
"workerCount": 10,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/User-RetrieveEmail.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 2000,
"workerCount": 25,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/User-Search.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 2000,
"workerCount": 25,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/User-SearchData.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"loopCount": 2000,
"workerCount": 25,
"workerCount": 100,
"workerFactory": {
"className": "io.fusionauth.load.FusionAuthWorkerFactory",
"attributes": {
Expand Down
4 changes: 2 additions & 2 deletions src/main/script/load-test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

#
# Copyright (c) 2022, FusionAuth, All Rights Reserved
# Copyright (c) 2022-2025, FusionAuth, All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,4 +33,4 @@ if [[ $# > 1 && $1 == "--suspend" ]]; then
shift
fi

~/dev/java/current17/bin/java ${suspend} -cp "${CLASSPATH}" io.fusionauth.load.LoadRunner $@
~/dev/java/current21/bin/java ${suspend} -cp "${CLASSPATH}" io.fusionauth.load.LoadRunner $@