Skip to content

feature: add feature/load engine#9

Merged
marr97 merged 2 commits intomainfrom
feature/load-engine
Mar 10, 2026
Merged

feature: add feature/load engine#9
marr97 merged 2 commits intomainfrom
feature/load-engine

Conversation

@marr97
Copy link
Collaborator

@marr97 marr97 commented Mar 5, 2026

What

Implement basic Load Engine with RPS throttling. The engine sends GET requests to a specified URL at a given rate and stops after the specified duration.

Changes:

  • Add LoadEngine class with start() and stop() methods
  • Add unit tests for RPS accuracy, duration, manual stop, and error handling

How to verify

./mvnw test

Closes #2

@marr97 marr97 force-pushed the feature/load-engine branch from 7ab7036 to 3c1b336 Compare March 5, 2026 19:13
@marr97 marr97 requested a review from devcrocod March 5, 2026 19:18
Copy link
Collaborator

@devcrocod devcrocod left a comment

Choose a reason for hiding this comment

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

left a few comments

}

try {
HttpResponse<String> response = sender.send(url);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use asynchronous sending (or a thread pool). Otherwise, the calls may block and the required RPC performance cannot be achieved

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a limitation of the current implementation. The next issue (#10 ) introduces Virtual Threads — each request will be submitted to a Virtual Thread pool so the main loop is not blocked.

Comment on lines +31 to +33
while (System.nanoTime() < sendNextTime) {
// busy-wait
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thread.sleep?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At high RPS sleep precision can become a problem — we can overshoot the interval. Should I combine both approaches (sleep for most of the wait, then busy-wait for the last ~1ms), or is Thread.sleep() acceptable for now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thread.sleep is a simple way, but there are other delay options
Using a loop doesn’t look very reliable to me

Comment on lines +18 to +19
this.targetRps = targetRPS;
this.durationSeconds = durationSeconds;
Copy link
Collaborator

Choose a reason for hiding this comment

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

validate values

private WireMockServer wireMock;
private String baseUrl;

@BeforeEach
Copy link
Collaborator

Choose a reason for hiding this comment

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

add AfterEach for closing sender

Comment on lines +25 to +26
try (HttpSender sender = new HttpSender()) {
sender.send(baseUrl + "/test");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

HttpClient warmup. The first request takes 2-3 seconds due to internal initialization. Without this RPS accuracy tests fail because most of the test duration is spent on the cold start.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In that case, it should be in the source code, not in the test code

@marr97 marr97 merged commit b2878d7 into main Mar 10, 2026
1 check passed
@marr97 marr97 deleted the feature/load-engine branch March 10, 2026 22:27
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.

Implement basic Load Engine with RPS throttling (GET requests)

2 participants