1 2 Previous Next 19 Replies Latest reply on Dec 8, 2009 1:47 PM by David Ward

    Performance Improvement Proposal: Cache result of HttpServle

    David Ward Master

      HttpMessageComposer.populateMessage(Message, T) calls a helper method, getRequestInfo(HttpServletRequest) every time. This method will call several of the accessor methods of HttpServletRequest to populate the HttpRequest meta information to set in the ESB Message Properties.

      One accessor method of HttpServletRequest stands out as being expensive: getLocalName(). This method under-the-hood calls java.net.InetAddress.getHostName()/getHostByAddr(), which accounted for 12.8% of the total testing time [1].

      The proposed fix is to cache the request's localName. So change this:

      requestInfo.setLocalName(request.getLocaleName());


      to this:

      requestInfo.setLocalName(getLocalName(request));
      
      private static final String getLocalName(HttpServletRequest request) {
       String localAddr = request.getLocalAddr();
       String localName = localAddr_to_localName.get(localAddr);
       if (localName == null) {
       synchronized (localAddr_to_localName) {
       localName = request.getLocalName();
       localAddr_to_localName.put(localAddr, localName);
       }
       }
       return localName;
      }
      private static final Map<String,String> localAddr_to_localName = new HashMap<String,String>();


      JProfiler proved this hot spot completely fell off the map once the fix was applied.

      [1]
      Test Details:
      - Web Service requests through new HttpGateway to a single-action chain calling the XsltAction.
      - 50 client threads
      - each Message size is <1k
      Server Environment:
      - Sun JDK 1.5.0_22
      - Fedora 11 (Linux 2.6.30.9-99.fc11.i686.PAE)
      - 4 gigs RAM, dual-core CPU
      - JBoss ESB 4.7
      Client Environment:
      - Sun JDK 1.6.0_17
      - Fedora 11 (Linux 2.6.30.9-99.fc11.i686.PAE)
      - 2 gigs RAM, dual-core CPU
      - soapUI 3.0.1

        1 2 Previous Next