eclipse-ee4j / eclipse-ee4j/jersey

Returning a complex Bean type from a resource method is very slow (Jackson provider)

Open
#3,714 4 comments 0 reactions 0 assignees View on GitHub
Component: performance
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Hello,

I integrated a new RESTful endpoint in an existing Tomcat project, using Jersey. I use Jackson as my JSON support provider. For test purposes, I have a pretty simple GET resource method that populates the Bean object and returns it.

My Bean class is pretty complex. I have around 20 bean model classes in total. They are interconnected in a (possibly) circular manner, as shown in the illustration below. Please note that the real scenario and more complex and branched. _(Note: The instances of those classes do not have any circular pointers. If a B2 instance points on a B1 instance, it is not the B1 it is contained in.)_
![image](https://user-images.githubusercontent.com/15966812/32836958-4bc8f5e2-ca14-11e7-88e3-afecaf7bf573.png)

My problem started by noticing that when I'm returning such a complex structure, the performance is just too slow. Getting an answer back takes "forever" (more than a few minutes). I tried reducing the complexity of the structure and the responses got quicker. My _estimate_ is that as the structure gets more complex, the response time gets longer in an exponential manner.

My initial thought was to put the blame on Jackson. So I tried to serialise the Bean into JSON inside the method and return the String of the JSON. All performance issues were solved.

I then tried to build a MessageBodyWriter and to serialise the Bean there. Also worked fine.

Hence, my current assumption is that maybe the default Writer, or some Mapper, are the cause of this problem. I'm wondering whether it is a bug in Jersey, or in the provider, or am I doing something wrong. Not sure how to proceed.

Would appreciate your help.

Thank you.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.