Skip to content

Commit 98b9ff6

Browse files
committed
Added /load/random and /load/securerandom
1 parent d8409ed commit 98b9ff6

File tree

7 files changed

+313
-1
lines changed

7 files changed

+313
-1
lines changed

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Load Simulator
2+
3+
4+
## How to Start the Load Simulator
5+
6+
### Ubuntu
7+
8+
```
9+
sudo apt install openjdk-21-jre-headless -y
10+
java --version
11+
wget https://github.com/tagitmobile/load-simulator/releases/download/v0.0.1/load-simulator-0.0.1.jar
12+
java -jar load-simulator-0.0.1.jar
13+
```
14+
15+
That's it!
16+
17+
## Benchmarking the Load Simulator
18+
19+
### Smoke Test
20+
21+
To test the simulate, use the following commands:
22+
23+
- `curl localhost:8080/load/simple`
24+
- `curl localhost:8080/load/random`
25+
- `curl localhost:8080/load/fibonacci`
26+
27+
You should see the following lines printed in the server.
28+
29+
```
30+
2024-12-19T14:36:46.900Z INFO 1544 --- [LoadSimulator] [mcat-handler-10] c.t.c.l.web.LoadTestController : Computation done. Sum = 1999999000000. Time elapsed = 9 ms. on VirtualThread[#42,tomcat-handler-10]/runnable@ForkJoinPool-1-worker-1
31+
32+
2024-12-19T14:37:22.744Z INFO 1544 --- [LoadSimulator] [mcat-handler-16] c.t.c.l.web.LoadTestController : Computation done. Sum of Random Numbers = 429836190657872. Time elapsed = 59 ms. on VirtualThread[#49,tomcat-handler-16]/runnable@ForkJoinPool-1-worker-2
33+
34+
2024-12-19T14:37:57.602Z INFO 1544 --- [LoadSimulator] [mcat-handler-18] c.t.c.l.web.LoadTestController : Computation done. Fib(35) = 9227465. Time elapsed = 40 ms. on VirtualThread[#51,tomcat-handler-18]/runnable@ForkJoinPool-1-worker-3
35+
```
36+
37+
### Benchmark
38+
39+
#### Install Apache HTTP Server Benchmarking Tool
40+
41+
https://httpd.apache.org/docs/2.4/programs/ab.html
42+
43+
```
44+
sudo apt install apache2-utils -y
45+
```
46+
47+
#### Run locally
48+
49+
```
50+
ab -n 10 -c 2 http://localhost:8080/load/simple
51+
```
52+
53+
#### Run remotely
54+
55+
##### Simple
56+
57+
```
58+
ab -n 10000 -c 8 http://ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com:8080/load/simple
59+
```
60+
61+
##### Random
62+
63+
```
64+
ab -n 1000 -c 8 http://ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com:8080/load/random
65+
```
66+
67+
Increase the number of requests `-n` and the concurrency `-c` accordingly to perform the load test.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = 'com.tagit.commons'
10-
version = '0.0.1-SNAPSHOT'
10+
version = '0.0.2'
1111

1212
java {
1313
toolchain {

results/m6a-random.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$ ab -n 1000 -c 8 http://ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com:8080/load/random
2+
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
3+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4+
Licensed to The Apache Software Foundation, http://www.apache.org/
5+
6+
Benchmarking ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com (be patient)
7+
Completed 100 requests
8+
Completed 200 requests
9+
Completed 300 requests
10+
Completed 400 requests
11+
Completed 500 requests
12+
Completed 600 requests
13+
Completed 700 requests
14+
Completed 800 requests
15+
Completed 900 requests
16+
Completed 1000 requests
17+
Finished 1000 requests
18+
19+
20+
Server Software:
21+
Server Hostname: ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com
22+
Server Port: 8080
23+
24+
Document Path: /load/random
25+
Document Length: 57 bytes
26+
27+
Concurrency Level: 8
28+
Time taken for tests: 49.143 seconds
29+
Complete requests: 1000
30+
Failed requests: 0
31+
Total transferred: 190000 bytes
32+
HTML transferred: 57000 bytes
33+
Requests per second: 20.35 [#/sec] (mean)
34+
Time per request: 393.144 [ms] (mean)
35+
Time per request: 49.143 [ms] (mean, across all concurrent requests)
36+
Transfer rate: 3.78 [Kbytes/sec] received
37+
38+
Connection Times (ms)
39+
min mean[+/-sd] median max
40+
Connect: 2 4 0.8 4 15
41+
Processing: 60 388 41.1 389 493
42+
Waiting: 60 388 41.1 388 493
43+
Total: 63 392 41.2 392 496
44+
45+
Percentage of the requests served within a certain time (ms)
46+
50% 392
47+
66% 411
48+
75% 421
49+
80% 426
50+
90% 443
51+
95% 457
52+
98% 471
53+
99% 478
54+
100% 496 (longest request)

results/m6a-simple.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$ ab -n 10000 -c 8 http://ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com:8080/load/simple
2+
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
3+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4+
Licensed to The Apache Software Foundation, http://www.apache.org/
5+
6+
Benchmarking ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com (be patient)
7+
Completed 1000 requests
8+
Completed 2000 requests
9+
Completed 3000 requests
10+
Completed 4000 requests
11+
Completed 5000 requests
12+
Completed 6000 requests
13+
Completed 7000 requests
14+
Completed 8000 requests
15+
Completed 9000 requests
16+
Completed 10000 requests
17+
Finished 10000 requests
18+
19+
20+
Server Software:
21+
Server Hostname: ec2-18-136-200-73.ap-southeast-1.compute.amazonaws.com
22+
Server Port: 8080
23+
24+
Document Path: /load/simple
25+
Document Length: 37 bytes
26+
27+
Concurrency Level: 8
28+
Time taken for tests: 24.348 seconds
29+
Complete requests: 10000
30+
Failed requests: 0
31+
Total transferred: 1700000 bytes
32+
HTML transferred: 370000 bytes
33+
Requests per second: 410.71 [#/sec] (mean)
34+
Time per request: 19.478 [ms] (mean)
35+
Time per request: 2.435 [ms] (mean, across all concurrent requests)
36+
Transfer rate: 68.19 [Kbytes/sec] received
37+
38+
Connection Times (ms)
39+
min mean[+/-sd] median max
40+
Connect: 2 7 59.5 3 1089
41+
Processing: 6 13 3.4 12 31
42+
Waiting: 6 13 3.4 12 31
43+
Total: 8 19 59.7 15 1104
44+
45+
Percentage of the requests served within a certain time (ms)
46+
50% 15
47+
66% 17
48+
75% 18
49+
80% 19
50+
90% 21
51+
95% 22
52+
98% 25
53+
99% 27
54+
100% 1104 (longest request)

results/m6g-random.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$ ab -n 1000 -c 8 http://ec2-13-251-106-123.ap-southeast-1.compute.amazonaws.com:8080/load/random
2+
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
3+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4+
Licensed to The Apache Software Foundation, http://www.apache.org/
5+
6+
Benchmarking ec2-13-251-106-123.ap-southeast-1.compute.amazonaws.com (be patient)
7+
Completed 100 requests
8+
Completed 200 requests
9+
Completed 300 requests
10+
Completed 400 requests
11+
Completed 500 requests
12+
Completed 600 requests
13+
Completed 700 requests
14+
Completed 800 requests
15+
Completed 900 requests
16+
Completed 1000 requests
17+
Finished 1000 requests
18+
19+
20+
Server Software:
21+
Server Hostname: ec2-13-251-106-123.ap-southeast-1.compute.amazonaws.com
22+
Server Port: 8080
23+
24+
Document Path: /load/random
25+
Document Length: 57 bytes
26+
27+
Concurrency Level: 8
28+
Time taken for tests: 109.785 seconds
29+
Complete requests: 1000
30+
Failed requests: 0
31+
Total transferred: 190000 bytes
32+
HTML transferred: 57000 bytes
33+
Requests per second: 9.11 [#/sec] (mean)
34+
Time per request: 878.279 [ms] (mean)
35+
Time per request: 109.785 [ms] (mean, across all concurrent requests)
36+
Transfer rate: 1.69 [Kbytes/sec] received
37+
38+
Connection Times (ms)
39+
min mean[+/-sd] median max
40+
Connect: 2 3 1.2 3 14
41+
Processing: 207 870 117.0 860 1437
42+
Waiting: 207 870 117.0 860 1437
43+
Total: 209 874 117.1 863 1440
44+
45+
Percentage of the requests served within a certain time (ms)
46+
50% 863
47+
66% 914
48+
75% 945
49+
80% 961
50+
90% 1017
51+
95% 1077
52+
98% 1144
53+
99% 1187
54+
100% 1440 (longest request)

results/m6g-simple.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
$ ab -n 10000 -c 8 http://ec2-13-251-106-123.ap-southeast-1.compute.amazonaws.com:8080/load/simple
2+
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
3+
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
4+
Licensed to The Apache Software Foundation, http://www.apache.org/
5+
6+
Benchmarking ec2-13-251-106-123.ap-southeast-1.compute.amazonaws.com (be patient)
7+
Completed 1000 requests
8+
Completed 2000 requests
9+
Completed 3000 requests
10+
Completed 4000 requests
11+
Completed 5000 requests
12+
Completed 6000 requests
13+
Completed 7000 requests
14+
Completed 8000 requests
15+
Completed 9000 requests
16+
Completed 10000 requests
17+
Finished 10000 requests
18+
19+
20+
Server Software:
21+
Server Hostname: ec2-13-251-106-123.ap-southeast-1.compute.amazonaws.com
22+
Server Port: 8080
23+
24+
Document Path: /load/simple
25+
Document Length: 37 bytes
26+
27+
Concurrency Level: 8
28+
Time taken for tests: 15.597 seconds
29+
Complete requests: 10000
30+
Failed requests: 0
31+
Total transferred: 1700000 bytes
32+
HTML transferred: 370000 bytes
33+
Requests per second: 641.15 [#/sec] (mean)
34+
Time per request: 12.478 [ms] (mean)
35+
Time per request: 1.560 [ms] (mean, across all concurrent requests)
36+
Transfer rate: 106.44 [Kbytes/sec] received
37+
38+
Connection Times (ms)
39+
min mean[+/-sd] median max
40+
Connect: 1 5 38.7 3 1074
41+
Processing: 4 7 2.7 7 37
42+
Waiting: 4 7 2.6 7 37
43+
Total: 5 12 38.8 10 1083
44+
45+
Percentage of the requests served within a certain time (ms)
46+
50% 10
47+
66% 11
48+
75% 11
49+
80% 12
50+
90% 14
51+
95% 16
52+
98% 20
53+
99% 24
54+
100% 1083 (longest request)

src/main/java/com/tagit/commons/loadsimulator/web/LoadTestController.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.security.SecureRandom;
44
import java.util.Arrays;
5+
import java.util.Random;
56

67
import org.springframework.web.bind.annotation.GetMapping;
78
import org.springframework.web.bind.annotation.RestController;
@@ -42,6 +43,33 @@ public String load2() {
4243
// Define a large size for the array
4344
int size = 400000;
4445

46+
// Create and populate a large array of random integers
47+
int[] numbers = new int[size];
48+
Random rand = new Random();
49+
for (int i = 0; i < size; i++) {
50+
numbers[i] = rand.nextInt(Integer.MAX_VALUE);
51+
}
52+
53+
// Sum the elements to generate CPU usage
54+
long sum = 0;
55+
for (int n : numbers) {
56+
sum += n;
57+
}
58+
59+
// Sort the array to increase CPU usage further
60+
Arrays.sort(numbers);
61+
long end = System.currentTimeMillis();
62+
long elapsed = end - start;
63+
log.info("Computation done. Sum of Random Numbers = " + sum + ". Time elapsed = " + elapsed + " ms. on " + Thread.currentThread().toString());
64+
return "Computation done. Sum of Random Numbers = " + sum;
65+
}
66+
67+
@GetMapping("/load/securerandom")
68+
public String load2b() {
69+
long start = System.currentTimeMillis();
70+
// Define a large size for the array
71+
int size = 400000;
72+
4573
// Create and populate a large array of random integers
4674
int[] numbers = new int[size];
4775
SecureRandom rand = new SecureRandom();
@@ -63,6 +91,7 @@ public String load2() {
6391
return "Computation done. Sum of Random Numbers = " + sum;
6492
}
6593

94+
6695
@GetMapping("/load/fibonacci")
6796
public String loadFibonacci() {
6897
long start = System.currentTimeMillis();

0 commit comments

Comments
 (0)