Skip to content

feature: add virtual threads to LoadEngine and validation tests#15

Merged
marr97 merged 2 commits intomainfrom
feature/engine-virtual-threads
Mar 15, 2026
Merged

feature: add virtual threads to LoadEngine and validation tests#15
marr97 merged 2 commits intomainfrom
feature/engine-virtual-threads

Conversation

@marr97
Copy link
Collaborator

@marr97 marr97 commented Mar 11, 2026

What

Upgrade LoadEngine to use Virtual Threads for request execution.
Each HTTP request is now submitted as a separate Virtual Thread task via ExecutorService,
so the main loop is no longer blocked waiting for responses.

Also added:

  • Input validation in LoadEngine constructor (null/empty URL, non-positive RPS/duration)
  • Replaced busy-wait with Thread.sleep() to reduce CPU usage
  • Tests for validation edge cases

How to verify

./mvnw test

Closes #10

@marr97 marr97 requested a review from devcrocod March 11, 2026 15:06
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not very clear why the tests were removed


try (HttpSender sender = new HttpSender()) {
try (HttpSender sender = new HttpSender();
ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of threads can grow without limit, and eventually no amount of memory will be enough

while (System.nanoTime() < sendNextTime) {
// busy-wait
}
long waitMillis = (sendNextTime - System.nanoTime()) / 1_000_000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this calculation, waitMillis may become 0, which will cause the sleep to be skipped and the requests to be sent immediately

log.error("Sender closed or failed to initialize", e);
}

running = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not obvious how the entire process terminates

@marr97 marr97 requested a review from p1gushka March 14, 2026 15:36
@marr97 marr97 merged commit b9ee156 into main Mar 15, 2026
1 check passed
@marr97 marr97 deleted the feature/engine-virtual-threads branch March 15, 2026 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce Virtual Threads in Load Engine

2 participants