Reputation: 409
I have a application that is using Spring Boot + JPA/Hibernate (DB being used is PostGresDB). I have a Controller method that returns back a JSONArray. The size of the array has gotten up to 3.4MB. I have noticed it is taking up to 30-35 seconds for a client to complete their request when retrieving this JSONArray. I checked the query that gets generated and that query itself finishes in 500ms so the DB isn't a really a problem. I imagine ~4MB of data is too much? I don't have much experience so was wondering if its expected to take this long. This is a webservice that is running on AWS on a stacked machine.
Any troubleshooting steps or insights on debugging or obvious things I should be doing. I looked into paginating the response but would like to avoid that if possible. Didn't think 3.4MB was that big.
Upvotes: 0
Views: 1250
Reputation: 164
First i would check if hibernate is the bottleneck. You can test this by wrapping your backend call in some logging code, see code below.
@RequestMapping("api")
public SomeObject getSomeObject() {
long start = System.currentTimeMillis();
// call the method that gets the object via JPA
System.out.println("Got all results in '" + (System.currentTimeMillis() - start) / 1000 + "' seconds");
}
If the result it outputs is > 30 seconds then you know hibernate is your bottleneck. If this is the case then you need to perform some pagination to limit the results you are returning to the client.
Upvotes: 0
Reputation: 29
How is the information being formed on the back end? Are JOINs / multiple tables involved? Try sending 4 MB of static data as a test and see how that does? (You may need to make a fake REST endpoint to do this, but if you can get the JSON once you should be able to save it off in a file or something ).
You may also be able to place timers n your code, or use a tool like JVisualVM to connect to the running process and collect method timing information. Looking at the "method self time" metric may be useful here if the problem is in your java code or its run time dependencies.
Upvotes: 2