korrawit
korrawit

Reputation: 1000

How do I calculate request time processing in JAX-WS?

I'm develop RESTful web service and I want to put the request time processing into xml response for all request.

I'm use Netbeans 6.9.1 and GlassFish version 3.

How can I measure ?

Thank you.

Upvotes: 1

Views: 1025

Answers (1)

Drew
Drew

Reputation: 1937

This is a bad idea for 2 reasons:

  1. That timing information is redundant. There is nothing to keep the consumer himself from starting a timer prior to calling your web service, and then stopping the timer when he gets the response back.
  2. If you try to automate the testing, you'll wind up having to ignore that timing information, since you can't predict that value. It makes it more difficult to test your web service, since the response is non-deterministic.

Now, it's good that you care about performance, but rather than return those metrics to the user, I would record those behind-the-scenes in your system logs, which you can review at any time. There's many ways to do that, but here are 2 common patterns.

  1. Use an Apache Commons logger and then do long start = System.currentTimeMillis() at the entry point to your code, another call to System.currentTimeMillis() at the exit point to your code, compute the difference, and just log.info() it out.
  2. The cleaner but harder to setup option is to use an Aspect like Spring Framework's PerformanceMonitorInterceptor.

Here's a working example I copied from a Spring Application Context file.

<bean id="springPerformanceMonitorAspectInterceptor" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor">
   <property name="loggerName" value="com.myProject.performanceMonitor" />
</bean>
<aop:config>
   <aop:pointcut id="springMonitoringPointcut" expression="execution(* com.myProject..*(..))" />
   <aop:advisor pointcut-ref="springMonitoringPointcut" advice-ref="springPerformanceMonitorAspectInterceptor" />
</aop:config>

Upvotes: 1

Related Questions