This project demonstrates and benchmarks different approaches for making 100 REST API calls from a Java application.
The main goal is to measure the performance impact of:
- Sequential API calls
CompletableFuturewith parallel execution- Application-level thread pooling
- HTTP connection pooling
- Java 17 vs Java 21
The project contains both the API client and the test API server, allowing the benchmark to be reproduced locally.
java-parallel-api-benchmark/
│
├── validation-client/
│ ├── pom.xml
│ └── src/
│ └── main/
│ └── java/
│ └── com/test/validation_client/
│
├── validation-server/
│ ├── pom.xml
│ └── src/
│ └── main/
│ └── java/
│ └── com/test/validation_server/
│
└── README.md
- API calls 100
- Application threads 10
- HTTP connections 10
- API type REST
- Client Spring RestClient
- HTTP client Apache HttpClient
- Measurement End-to-end execution time
| Java Version | Execution Model | Threads | HTTP Pool | Total Time | Improvement |
|---|---|---|---|---|---|
| Java 21 | Sequential | 1 | — | 101,741 ms | — |
| Java 21 | CompletableFuture | 10 | Default | 10,533 ms | 89.6% |
| Java 21 | CompletableFuture | 10 | 10 | 10,329 ms | 89.8% |
| Java 17 | Sequential | 1 | — | 101,672 ms | — |
| Java 17 | CompletableFuture | 10 | Default | 20,421 ms | 79.9% |
| Java 17 | CompletableFuture | 10 | 10 | 10,366 ms | 89.8% |
Test: 100 PRID validation API calls -Concurrency: 10 parallel requests -Measurement: End-to-end execution time for processing all 100 requests.
Key Observations
- Sequential execution takes approximately 101 seconds for 100 API calls.
- Using CompletableFuture with 10 concurrent threads reduces execution time to approximately 10 seconds.
- Configuring the HTTP connection pool to match the application concurrency significantly improves performance in the Java 17 setup.
- Java 17 and Java 21 show nearly identical performance when both are configured with 10 application threads and 10 HTTP connections.
- The primary performance improvement comes from parallel I/O and proper HTTP connection pooling, rather than the Java version itself.
The results can be summarized as:
Sequential
~101.7 seconds
│
│ CompletableFuture + 10 threads
▼
Java 17 ~20.4 seconds
Java 21 ~10.5 seconds
│
│ HTTP Connection Pool(10)
▼
Java 17 ~10.4 seconds
Java 21 ~10.3 seconds
100 PRIDs
│
▼
CompletableFuture
│
▼
ExecutorService
10 threads
│
▼
RestClient
│
▼
Apache CloseableHttpClient
│
▼
PoolingHttpClientConnectionManager
│
HTTP Pool (10)
│
┌──────────────┼──────────────┐
▼ ▼ ▼
C1 C2 ... C10
│ │ │
└──────────────┼──────────────┘
▼
Validation Server
│
▼
Response
Note: These are initial benchmark results from a local/test environment. For a rigorous comparison, multiple runs with average, median, and P95 latency should be recorded.