eclipse-ee4j / eclipse-ee4j/jersey
High latency in Jersey when using immutable types in response
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hi
We did performance testing of our application that used Jersey and figured out that response time is very big when we returned immutable object.
So here is our REST-service:
```
@Path("benchmark")
public class BenchmarkResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public List findAll() {
return List.of(new BenchmarkDTO(1, "Jersey"));
}
```
BenchmarkDTO is just simple DTO class. We used Wrk performance tool and average latency is about 350 ms even for small number of users (100). Then we changed the last line to :
`return Collections.singletonList(new BenchmarkDTO(1, "Jersey"));`
And latency remained the same. And finally we used mutable type as a response:
`return new ArrayList<>(List.of(new BenchmarkDTO(1, "Jersey")));`
And latency was acceptable now (1.8 ms).
Jersey: 3.1.1
Contributor guide
Research direction
Start with the BenchmarkResource.findAll response and the three return forms shown in the issue. Reproduce the latency difference on Jersey 3.1.1 using the mentioned wrk benchmark, then investigate why immutable response lists behave differently. Done means the reported latency gap is explained and corrected or documented with a reproducible result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100