Skip to content

Commit 56bbb8d

Browse files
committed
extended load endpoint
1 parent f8bd06c commit 56bbb8d

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/main/java/org/springframework/samples/petclinic/clinicactivity/ClinicActivityController.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,32 @@ public ResponseEntity<String> createLockContentionLoad(@RequestParam(name = "thr
194194
* Focuses on disk I/O bottlenecks that can be improved by faster storage or read replicas
195195
*/
196196
@PostMapping("/io-intensive-load")
197-
public ResponseEntity<String> createIOIntensiveLoad(@RequestParam(name = "duration", defaultValue = "5") int durationMinutes) {
198-
logger.warn("Received request to create I/O INTENSIVE LOAD for {} minutes - This will MAX OUT disk I/O operations!", durationMinutes);
197+
public ResponseEntity<String> createIOIntensiveLoad(@RequestParam(name = "duration", defaultValue = "5") int durationMinutes,
198+
@RequestParam(name = "threads", defaultValue = "6") int numThreads,
199+
@RequestParam(name = "limit", defaultValue = "400000") int limit) {
200+
logger.warn("Received request to create I/O INTENSIVE LOAD for {} minutes with {} threads and {} limit - This will MAX OUT disk I/O operations!",
201+
durationMinutes, numThreads, limit);
199202
if (durationMinutes <= 0) {
200203
return ResponseEntity.badRequest().body("Duration must be a positive integer.");
201204
}
202205
if (durationMinutes > 60) {
203206
return ResponseEntity.badRequest().body("Duration too high for I/O intensive load - maximum 60 minutes to prevent storage overload.");
204207
}
208+
if (numThreads <= 0) {
209+
return ResponseEntity.badRequest().body("Number of threads must be a positive integer.");
210+
}
211+
if (numThreads > 20) {
212+
return ResponseEntity.badRequest().body("Too many threads for I/O intensive load - maximum 20 to prevent system crash.");
213+
}
214+
if (limit <= 0) {
215+
return ResponseEntity.badRequest().body("Limit must be a positive integer.");
216+
}
217+
if (limit > 1000000) {
218+
return ResponseEntity.badRequest().body("Limit too high for I/O intensive load - maximum 1,000,000 to prevent excessive resource usage.");
219+
}
205220
try {
206-
dataService.createIOIntensiveLoad(durationMinutes);
207-
return ResponseEntity.ok("Successfully completed I/O INTENSIVE LOAD for " + durationMinutes + " minutes - Disk I/O was maxed out!");
221+
dataService.createIOIntensiveLoad(durationMinutes, numThreads, limit);
222+
return ResponseEntity.ok("Successfully completed I/O INTENSIVE LOAD for " + durationMinutes + " minutes with " + numThreads + " threads and " + limit + " limit - Disk I/O was maxed out!");
208223
} catch (Exception e) {
209224
logger.error("Error during I/O intensive load", e);
210225
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error during I/O intensive load: " + e.getMessage());

src/main/java/org/springframework/samples/petclinic/clinicactivity/ClinicActivityDataService.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,25 +411,24 @@ else if (operationCount % 5 == 3) {
411411
* Uses simple queries with large data transfers to keep I/O busy while minimizing CPU/Memory usage
412412
* Focuses on disk I/O bottlenecks that can be improved by faster storage or read replicas
413413
*/
414-
public void createIOIntensiveLoad(int durationMinutes) {
415-
logger.warn("Starting I/O INTENSIVE load test for {} minutes - This will MAX OUT disk I/O operations!", durationMinutes);
414+
public void createIOIntensiveLoad(int durationMinutes, int numThreads, int limit) {
415+
logger.warn("Starting I/O INTENSIVE load test for {} minutes with {} threads and {} limit - This will MAX OUT disk I/O operations!",
416+
durationMinutes, numThreads, limit);
416417
long startTime = System.currentTimeMillis();
417418
long endTime = startTime + (durationMinutes * 60 * 1000L);
418419

419420
try {
420421
AtomicInteger globalOperationCount = new AtomicInteger(0);
421422
List<Thread> threads = new ArrayList<>();
422423

423-
// Use fewer threads than CPU intensive to minimize CPU usage (focus on I/O)
424-
int numThreads = 6;
425-
logger.info("Creating {} I/O intensive threads (fewer than CPU load to focus on disk I/O)...", numThreads);
424+
logger.info("Creating {} I/O intensive threads with {} record limit per query...", numThreads, limit);
426425

427426
// Create I/O intensive threads
428427
for (int t = 0; t < numThreads; t++) {
429428
final int threadId = t;
430429
Thread ioThread = new Thread(() -> {
431430
try {
432-
executeIOIntensiveThread(threadId, endTime, globalOperationCount);
431+
executeIOIntensiveThread(threadId, endTime, globalOperationCount, limit);
433432
} catch (Exception e) {
434433
logger.error("Error in I/O intensive thread {}", threadId, e);
435434
}
@@ -456,21 +455,21 @@ public void createIOIntensiveLoad(int durationMinutes) {
456455
}
457456

458457
long actualEndTime = System.currentTimeMillis();
459-
logger.warn("Completed I/O INTENSIVE load test in {} ms. Total operations: {}",
460-
(actualEndTime - startTime), globalOperationCount.get());
458+
logger.warn("Completed I/O INTENSIVE load test in {} ms with {} threads and {} limit. Total operations: {}",
459+
(actualEndTime - startTime), numThreads, limit, globalOperationCount.get());
461460

462461
} catch (Exception e) {
463462
logger.error("Error during I/O intensive load test", e);
464463
throw new RuntimeException("Error during I/O intensive load test: " + e.getMessage(), e);
465464
}
466465
}
467466

468-
private void executeIOIntensiveThread(int threadId, long endTime, AtomicInteger globalOperationCount) {
467+
private void executeIOIntensiveThread(int threadId, long endTime, AtomicInteger globalOperationCount, int limit) {
469468
Random random = new Random();
470469
Faker faker = new Faker(new Locale("en-US"));
471470
int localOperationCount = 0;
472471

473-
logger.info("I/O Thread {} starting I/O intensive operations...", threadId);
472+
logger.info("I/O Thread {} starting I/O intensive operations with {} record limit...", threadId, limit);
474473

475474
while (System.currentTimeMillis() < endTime) {
476475
try {
@@ -481,7 +480,7 @@ private void executeIOIntensiveThread(int threadId, long endTime, AtomicInteger
481480
"FROM clinic_activity_logs " +
482481
"WHERE LENGTH(payload) > 100 " +
483482
"ORDER BY random()" +
484-
"LIMIT 350000");
483+
"LIMIT " + limit);
485484

486485

487486
localOperationCount++;

0 commit comments

Comments
 (0)