Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java web application gets slower if running a day

I am developing a java web application using the apache wicket framework and Eclipselink with PostgreSQL for OR mapping.

If i run the application (on localhost or on a remote server) everything is fast and useable. There are only five users at the moment. After about a day, some parts of the application start getting slow. Especially pages that use data from the database and an autocomplete function which uses data from OWL files. Static pages load quite fast.

Any ideas how to find the problem?

EDIT:

Thanks for your reply. The problem seems to be the memory usage generated by the sessions. That explains why i can't reproduce the issue on my local machine with only one user. A quick fix for me was increasing the heap size (-Xmx and -Xms) when starting Tomcat. Now i will go deeper into the wicket pages and find the memory-consuming models.

like image 429
Martin Schlagnitweit Avatar asked Dec 27 '22 16:12

Martin Schlagnitweit


1 Answers

Wicket demands some pretty solid coding practices around the "weight" of the serialized page. Serialized pages get stored in the Session and, if you fail to detach any class-level models, the data gets serialized, too. Before I realized this, I saw Session sizes approaching several hundred MB because I was serializing half my database queries!

So, a few things that might help:

Override your session store to warn you when you modify if the session is too big.

 public class CustomSessionStore extends SecondLevelCacheSessionStore {

    @Override
    public void setAttribute(Request request, String name, Object value) {
        super.setAttribute(request, name, value);

        if (Session.get().getSizeInBytes() > SESSION_WARN_LIMIT) {
            log.warn("Session Size is {} bytes", Session.get().getSizeInBytes());
        }
    }
 }

Make sure you detach your models:

public class MyPage extends WebPage {

    IModel<HeavyDataObject> heavyModel;

    @Override
    public void onDetach() {
        if (heavyModel != null)
            heavyModel.detach();
    }

}

Use the wicket developer tools to monitor various data sizes/stores while the application is running. The maven dependency is org.apache.wicket wicket-devutils

Hope that helps!

like image 146
jbrookover Avatar answered Dec 30 '22 06:12

jbrookover