JSP Struts performance / memory hints

I am working on a basic Struts application that is experiencing severe spikes in memory. We have a monitoring tool that will notice one request for every user adding 3MB to the JVM heap. Are there any tips for encouraging earlier garbage collection, freeing up memory, or improving performance?

The application is the main Struts application, but there are many rows in the JSP report, so many objects can be created. But this is not something you haven't seen before.

  • Run a set of queries against the database.
  • Create a serialized POJO bean. This is a string.
  • Add a string to a list of arrays.
  • Give a list of arrays to the form object when calling the action.
  • The JSP logic will iterate over the list from the ActionForm and the data is displayed to the user.

Notes:
1. The form is in the session area and possibly in the list of datasets (this may be the problem).
2. POJO bean contains 20 or so fields, combination of data String

or BigDecimal

.

The report can contain from 300 to 1200 lines. In this way, at least many objects are created.

+1


source to share


3 answers


  • List item

When setting up reports to be displayed in a web application, consider the number of records retrieved from the database.

If the number of records is large and the total set of records takes up a lot of memory, consider using pagination.



As far as possible, donot is called explicitly by the garbage collector. This happens for two reasons:

  • Garbage collection is an expensive process because it scans all memory.

  • Most production servers are configured at the JVM level to avoid explicit build garages

0


source


Given the information you provided, I would estimate that you would typically load 1 to 2 megabytes of data for the result: 750 rows * 20 fields * 100 bytes per field = 1.4 MB. Now let's take a look at all the temporary objects needed between the database and the final markup. 3 MB is not surprising.



My only concern is that this memory has leaked; those. the next generation space garbage collection does not collect all of these objects.

+2


source


I believe the problem lies with the arraylist in the ActionForm, which should allocate a huge chunk of memory space. I would write the query results directly into the answer: read a row from the result set, write to the response, read the next line, write, etc. It might not be MVC, but it would be better for your heap :-)

ActionForms are great for CRUD operations, but for reports ... I don't think so.

Note. If the ActionForm has scope = session, the instance will live (along with a huge arraylist) until the session expires. If scope = request, the instance will be available to GC.

0


source







All Articles