• tomcat打印接口延迟时间


    项目中有些页面时延不稳定,需要看每次接口调用时延,怎么看,有两种方法:一种是直接去catalina.out日志中看,一种是直接去localhost_access_log日志中看,第一种需要在代码中实现时延的计算,第二种方法只需在server.xml中加一个简单的配置。这里只说第二种:

      1、打开tomcat下conf/server.xml,先看Host节点配置:

    复制代码
    复制代码
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
    
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
    
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html
                 Note: The pattern used is equivalent to using pattern="common" -->
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
          </Host>
    复制代码
    复制代码

      2、这时localhost_access_log最后一个是文件大小:

    10.73.154.72 - - [12/Mar/2018:10:04:47 +0800] "POST /ms.sns.snsService/rewardHis HTTP/1.1" 200 133

      3、在conf/server.xml的Host节点中Value节点最后的pattern参数中添加% D

            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b %D" />

      4、重新打开localhost_access_log,加上了时延大小,单位是毫秒:

    10.125.40.179 - - [21/May/2018:14:12:22 +0800] "POST /ms.bkticket.myBookTicketService/getBookTicketRechargeList HTTP/1.1" 200 2519 62
    10.125.40.179 - - [21/May/2018:14:12:22 +0800] "POST /ms.bkticket.myBookTicketService/getBookTicketRemainBalance HTTP/1.1" 200 589 72
    10.125.40.179 - - [21/May/2018:14:12:23 +0800] "POST /ms.bkticket.myBookTicketService/getBookTicketRechargeList HTTP/1.1" 200 2096 47
  • 相关阅读:
    python(day1-11)
    如何进行测试管理
    为什么你参加了那么多培训,却依然表现平平?
    数据库总结
    为何大量网站不能抓取?爬虫突破封禁的6种常见方法
    re--读书笔记【转】
    re--findall 【转】
    re--参考手册
    bs4--官文--遍历文档树
    rhel6+apache2.4+mysql5.7+php5.6部署LAMP架构
  • 原文地址:https://www.cnblogs.com/wuzm/p/11753659.html
Copyright © 2020-2023  润新知