Database Reference
In-Depth Information
With these values and the user response time—which you can easily measure with a watch if you have access to
the application—you can break up the response time in a way similar to Figure 1-7.
In practice, you can't easily add the instrumentation code wherever you want. In the case of Figure 2-5 , you
have two problems. The first is that the servlet ( FrameworkServlet ) is a class provided by the Spring framework.
Therefore, you don't want to modify it. The second is that the data access object ( AccountDao ) is just an interface used
by the persistence framework (iBatis in this case). Therefore, you can't add code to it either. For the first problem,
you could create your own servlet that inherits from FrameworkServlet by simply adding the instrumentation code.
For the second one, you could decide to instrument the call to the persistence framework for the sake of simplicity.
This shouldn't be a problem because the database itself is already instrumented, and so, if necessary, you're able to
determine the overhead of the persistence framework itself.
Now that you've seen how to decide where the instrumentation code should be added, we can take a look at
a concrete example of how to implement it in the application code. Afterward, we'll examine an Oracle-specific
instrumentation of database calls.
Application Code
In general, the instrumentation code is implemented by taking advantage of an already available logging framework.
The reason is simple: it isn't easy to write a fast and flexible logging framework. Using an available framework
therefore saves quite a lot of development time. In fact, the major drawback of logging is that it can slow down the
application if not properly implemented. To avoid this, developers shouldn't only be careful to limit the verbosity of
logging but should also implement it with an efficient logging framework.
The Apache Logging Services Project 3 provides very good examples of logging frameworks. The core of
the project is log4j, a logging framework written for Java. Because of its success, having been ported to other
programming languages like C++, .NET, Perl, and PHP. I'll provide an example here based on log4j and Java.
For example, if you want to instrument the response time of the handleRequest method in the SignonController
servlet described in Figure 2-5 , you could write the following code:
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception
{
if (logger == null)
{
logger = Log4jLoggingHelper.getLog4jServerLogger();
}
if (logger.isInfoEnabled())
{
long beginTimeMillis = System.currentTimeMillis();
}
ModelAndView ret = null;
String username = request.getParameter("username");
// here the code handling the request...
 
 
Search WWH ::




Custom Search