Home     RSSRSS

Posts Tagged ‘Session’

Log the Servlet Processing Time

January 12, 2014 by kiranbadi1991 | Comments Off on Log the Servlet Processing Time | Filed in Development, Environment, Performance Engineering

Recently one of my friend who had a Java based web application which was was recently developed and deployed in the production environment was facing some performance issues contacted me. For some reasons in that application couple of functionality was taking more time to show up than few other functionalities, after doing some investigation, we realized that couple of servlets were taking more time than others for processing on the server side. First we identified servlets, then identified DAO associated with those servlets and then finally queries associated with that DAO.Once queries were identified we did some load testing for those queries using different data sets.

We used the below program to gather the required information about the servlet processing time,

import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
 
@WebListener
public class logprocessingtime implements ServletRequestListener {
    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        ServletRequest servletRequest = sre.getServletRequest();
        servletRequest.setAttribute("start", System.nanoTime());
    }
 
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        ServletRequest servletRequest = sre.getServletRequest();
        Long start = (Long) servletRequest.getAttribute("start");
        Long end = System.nanoTime();
        HttpServletRequest httpServletRequest =
                (HttpServletRequest) servletRequest;
        String uri = httpServletRequest.getRequestURI();
        System.out.println("time taken to execute servlet " + uri + ":" + ((end - start) / 1000) + "microseconds");
    }
}

The above java program is basically a web listener which we registered it to the servlet container and it listens for every request that web application receives. For every request the application receives we log the response time taken for it to process the request.

This program meets the servlet 3.0 Specs and in case if you want it to port to 2.4 , then probably you need to register the listener with web.xml.

More information about Servlet Request listener can be found here. Its powerful interface and it helps to get lot of troubleshooting information.

Tags: , , ,

Basics of LoadBalancing for Performance Engineer

October 22, 2011 by kiranbadi1991 | 1 Comment | Filed in Development, IP Spoofing, Load Balancer, Performance Engineering

One of the skillsets required to be successful performance engineer is knowing and understanding as how Load balancing works and what are the most frequent algorithms applications use and how these algorithms can impact or mitigate the performance issues and bring about the good user experiences.

We do Load balancing to spread the incoming requests across various backend servers which is also called as server farm so as to optimize and provide good user experience.Often,single machine is not sufficient to service the growing business requirement.We need lot of servers in the backend to service the growing requests coming from the clients.

There are different ways by which load balancing can be done, we can have hardware based load balancing,Network based Load Balancing and also software  based load balancing.Hardware based load balancing is mostly used by cloud service providers as requests to routed to the servers based on various network factors.For this discussion, I would like to talk more on the software based algorithms here used by the load balancers.Some of the commonly used load balancing ways are

  • Round Robin : In Round Robin style of Load Balancing,requests are routed to the backend servers based on round robin fashion,first request goes to server 1, then request goes to server 2…This pattern is followed till the request reaches the last server on the farm.Round Robin normally gives a good connection balance across the servers and this is one of most commonly used algorithm used.
  • Least Connection: In Least connection style, requests are routed to the servers which has got least number of connections to present at that point of time.If the server is overloaded , then connections or requests are not send to that server.Least connection is useful whenever we have resource contentions and whenever we need extract a full value of the box.Normally the application needs to tuned appropriately so that servers can be utilized to the max extent.
  • Weighted Connection: This is hybrid process which  can use the techniques of round robin and Least connections.Here the certain amount of points or percentages are allocated to individual server boxes in the backend and load balancer directs the traffic according to the weighted rule to the backend systems.Weighted connections are normally beneficial in the shared environments where applications share the resources.

In addition to above three methods, there might also be vendor or situation specific algorithms which can used.Most Load Balancer vendors provide a support where in load balancing can be done via custom implementation by writing some rules.So it makes sense for the performance Engineer to clarify algorithm rather than assuming it.Server Affinity/Persistence/Stickiness normally goes hand in hand with Load Balancer but however they are two different topics to discuss.

In order to select or suggest the correct algorithms, one also needs to have complete understanding of the platforms which is going to be hosted on the servers.Applications storing sessions in server process or storing in cookies might require persistence  to the instance of the server which is serving the requests,so in this either of these 3 methods might not be sufficient, we might needs a extra stuff to maintain a persistence.Applications storing the sessions in the databases can use any of the these of methods but might have some performance impact, as it might need to do some round trips to retrieve and validate sessions.

Hope this helps.

Tags: , , ,