Announcement Announcement Module
No announcement yet.
Speeding up jsp:include view Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Speeding up jsp:include view

    Hi Folks,

    I'm thinking of the way to speed up many things in my relatively slow working project. The victim I have selected from many others is a fragment of page that is printing out some excerpt of information from the database.

    jsp looks like this:
    <jsp:include page="/home/" flush="true" />
    The DAO methods as well as the domain elements are being cached with ehcache, so if everything is in cache, it works instantly and doesn't raise any performance issues, although if the the extraction DAO method and/or domain elements ain't in cache yet or got expired, the user who's getting on the page like this (the winner will feel on his onw how difficult it is for the server to include the to the generated page. Basically it could take 2-3 seconds in the most worse case to accomplish all the DB interactions without cache here. And during all this time the user sees the black rectangle right in the middle of the page

    So my idea was to think out some universal way of how to speed it all up. And here is what I did. Taking into the account the singleton-nature of all the beans in spring, in HomeController I have created the following member variable:

    public class HomeController extends MultiActionController {
      volatile Map<String, ModelAndView> cachedHeavyFragmentViews =
            Collections.synchronizedMap(new HashMap<String, ModelAndView>());
    and used it further like this:

    public ModelAndView heavyFragment(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        /// --- many heavy operations here --
        ModelAndView mav = new ModelAndView("heavyFragment");
        // ---- and here
        cachedHeavyFragmentViews.put( RequestHelper.getSafeLocaleAsString(req), mav );
        return mav;
    public ModelAndView heavyFragmentLight(HttpServletRequest req, HttpServletResponse resp) throws Exception {
            ModelAndView mav = cachedHeavyFragmentViews.get( RequestHelper.getSafeLocaleAsString(req) );
            if (mav == null)
                mav = new ModelAndView("notInitializedView");
            return mav;
    So, here we go. I set up a cron job that pulls /home/ periodically (every 3-5 mins) and the users are getting the prepared ModelAndView for their locale without delays. I have excluded the possibility when the winner gets on the real heavyFragmnet with this technique, loosing at the same moment the possibility to get the most fresh version of information right from the database. But it's ok, I can live with it.

    jsp looks like this now:
    <jsp:include page="/home/" flush="true" />
    The first thing - it works as it was supposed to work, and it has really increased the performance.

    The second thing is the question. Is that the right way of doing things? Or there is some official "Spring" way of doing this? What do you think, guys?

  • #2
    And? Nobody tried to increase the performance like that?