Other Factors

Buffering

Providing larger buffers for the HTTP Listeners allows more efficient processing and generation of content, with less blocking and content switching. It also allows the TCP/IP protocol to more efficiently run it's sliding window protocol and avoid network latencies. Prior to Jetty release 4.2.10, the default buffer size was 4096 bytes. This has now been increased to 8192 bytes. The buffer size can be set as follows:


  ...
 
    
      
        8080
        80
        200
        30000
        2500
        Listener
        8192
      
    
  
  ...

Security

Authenticated security constraints on a webapp can be expensive to check as often a realm is implemented using crypto algorithms or with a remote AAA server or database involved.

Frequently a webapp page is constructed with many images that are not sensitive and do not need to be protected with an authenticated security constraint. Significant performance gains can be obtained by excluding such static resources from a security constraint.

For example consider a webapp that protects the directory /private with an authenticated constraint, but has a number of non-sensitive images in the /private/images directory, then the following web.xml excerp can be used to protect the private directory without the expense of protecting the images directory.

  ...
  
    
      Authed User Required
      /private/*
    
    
      *
    
  
  
  
    
      Images Not Protected
      /private/images/*
      GET
      HEAD
    
  

Logging

Logging of requests can add extra CPU load per request and an extra synchronization point. The following points should be considered to optimize the logging configuration:

  • Is logging really required? Many webapps collect requests logs that are never viewed or analyzed. If the logs are unlikely to be used, then it would be better to not generate them. Note that there is a security audit aspect to collecting request logs that may require them to be generated even if seldom viewed.
  • Is the extended log format required? The extra content of the extended log is only useful if detailed log analysis is being performed.
  • Are all request required to be logged? Images and style sheets often do not add any significant information to a request log. The ignorePaths attribute of the NCSARequestLog class can be used to exclude some paths from the log.
  • Turn off buffering.

The following request log configuration applies the points above.


  ...
  
    
      ./logs/yyyy_mm_dd.request.log
      false
      90
      true
      false
      GMT
      
        
          /images/*
          *.css
        
      
    
  
  ...

Application

The way a web application is written can greatly effect the efficiency of the service. The following points should be considered when writing or reviewing your webapplication:

  • Do not flush the response output stream or writers. This can result in inefficient packet fragmentation.
  • If possible, implement the HttpServlet.getLastModfied() method so that content is only generated and served if the browser does not have a cached copy of the page.
  • If possible, set the content length of the content served. This allows simple persistent connections for both HTTP/1.0 and HTTP/1.1 clients.