【问题标题】:How do I calculate request time processing in JAX-WS?如何计算 JAX-WS 中的请求时间处理?
【发布时间】:2011-05-09 12:08:54
【问题描述】:

我正在开发 RESTful Web 服务,我想将请求时间处理放入所有请求的 xml 响应中。

我使用的是 Netbeans 6.9.1 和 GlassFish 版本 3。

如何测量?

谢谢。

【问题讨论】:

    标签: java rest glassfish jax-ws


    【解决方案1】:

    这是一个坏主意,原因有两个:

    1. 计时信息是多余的。没有什么可以阻止消费者自己在调用您的 Web 服务之前启动计时器,然后在收到响应时停止计时器。
    2. 如果您尝试自动化测试,您最终将不得不忽略该时间信息,因为您无法预测该值。由于响应是不确定的,因此测试 Web 服务变得更加困难。

    现在,您关心性能是件好事,但我不会将这些指标返回给用户,而是将这些幕后花絮记录在您的系统日志中,您可以随时查看。有很多方法可以做到这一点,但这里有两种常见的模式。

    1. 使用 Apache Commons 记录器,然后在代码的入口点执行 long start = System.currentTimeMillis(),在代码的出口点再次调用 System.currentTimeMillis(),计算差异,然后只需 log.info() 输出。李>
    2. 更简洁但更难设置的选项是使用像 Spring Framework 的 PerformanceMonitorInterceptor 这样的方面。

    这是我从 Spring 应用程序上下文文件中复制的一个工作示例。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 2020-10-17
      • 2011-07-02
      • 2016-05-10
      • 1970-01-01
      相关资源
      最近更新 更多