spring boot 性能测试工具汇总logback异步日志分析
Posted 红桃xin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot 性能测试工具汇总logback异步日志分析相关的知识,希望对你有一定的参考价值。
1. 使用JMeter进行简单的带json数据的post请求测试
https://www.jianshu.com/p/b61f70b67266
2. jmeter&badboy做压力测试
https://www.cnblogs.com/happy-today/p/7852277.html
3. 实操-logback异步日志分析对比
- 接口耗时对比,
50个线程,每个线程循环次数50次
异步比同步少了20ms
异步日志
实时
- logback文件
<?xml version="1.0" encoding="UTF-8"?>
<!-- 从高到低:OFF,FATAL,ERROR,WARN,INFO,DEBUG,TRACE,ALL -->
<!-- 日志输出规则:输出比当前ROOT级别高的日志,另外亦可考虑filter级别过滤器 -->
<!-- scan=true,一旦配置文件发生改变,将会被重新加载,默认为true; scanPeriod,监测配置文件是否有修改的时间间隔,默认单位是毫秒,scan为true才生效,默认的时间间隔为1分钟; debug=true,打印logback内部日志信息,实时查看logback运行状态,默认为false; -->
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProperty scope="context" name="applicationName" source="spring.application.name"/>
<!-- 项目名 -->
<property name="prjName" value="zat-life-product-service"/>
<!-- 应用名 -->
<property name="appName" value="zatLifeProductService"/>
<!-- 定义日志文件位置 -->
<property name="logDir" value="/alidata1/admin"/>
<!-- 日志最大历史30天 -->
<property name="maxHistory" value="30"/>
<!-- 部署类型 -->
<property name="source" value="micro"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder charset="UTF-8">
<pattern>%magenta(%d{HH:mm:ss:SSS} [%thread]) %cyan(%-5p) %green([%C{0}.%M:%L])--%msg%xEx%n</pattern>
</encoder>
</appender>
<appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logDir}/${prjName}/logs/debug-%d{yyyy-MM-dd}-ss_${source}_app_${appName}_lt_debug.log
</FileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %-5p [%c] [%F:%L][trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-},parent=%X{X-Parent-Id:-},name=%X{X-Span-Name:-},app=%X{appName:-},begintime=%X{begintime:-},endtime=%X{fin-X1-time:-}] - %msg%n
</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level> <!-- 只打印Debug日志 -->
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logDir}/${prjName}/logs/info-%d{yyyy-MM-dd}-ss_${source}_app_${appName}_lt_info.log
</FileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %-5p [%c] [%F:%L]
[trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-},parent=%X{X-Parent-Id:-},name=%X{X-Span-Name:-},app=%X{appName:-},begintime=%X{begintime:-},endtime=%X{fin-X1-time:-}] - %msg%n
</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level> <!-- 只打印Info日志 -->
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logDir}/${prjName}/logs/warn-%d{yyyy-MM-dd}-ss_${source}_app_${appName}_lt_warn.log
</FileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %-5p [%c] [%F:%L][trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-},parent=%X{X-Parent-Id:-},name=%X{X-Span-Name:-},app=%X{appName:-},begintime=%X{begintime:-},endtime=%X{fin-X1-time:-}] - %msg%n
</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level> <!-- 只打印Warn日志 -->
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${logDir}/${prjName}/logs/error-%d{yyyy-MM-dd}-ss_${source}_app_${appName}_lt_error.log
</FileNamePattern>
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%d [%thread] %-5p [%c] [%F:%L][trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-},parent=%X{X-Parent-Id:-},name=%X{X-Span-Name:-},app=%X{appName:-},begintime=%X{begintime:-},endtime=%X{fin-X1-time:-}]- %msg%n
</pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level> <!-- 只打印Error日志 -->
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 异步输出DEBUG日志 -->
<appender name="DEBUG_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>512</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="DEBUG_FILE"/>
</appender>
<!-- 异步输出INFO日志 -->
<appender name="INFO_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>512</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="INFO_FILE"/>
</appender>
<!-- 异步输出WARN日志 -->
<appender name="WARN_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>512</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="WARN_FILE"/>
</appender>
<!-- 异步输出ERROR日志 -->
<appender name="ERROR_ASYNC" class="ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold>0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>512</queueSize>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref="ERROR_FILE"/>
</appender>
<!--控制框架输出日志-->
<logger name="org.apache" level="INFO"/>
<logger name="org.springframework" level="INFO"/>
<logger name="com.zatech" level="INFO"/>
<logger name="com.zhongan" level="INFO"/>
<springProfile name="prd">
<root>
<level value="INFO"/>
<appender-ref ref="INFO_ASYNC"/>
<appender-ref ref="WARN_ASYNC"/>
<appender-ref ref="ERROR_ASYNC"/>
</root>
</springProfile>
<springProfile name="dev,test,uat,pre">
<root>
<level value="INFO"/>
<appender-ref ref="STDOUT"/>
<!-- 异步文件输出 -->
<!-- <appender-ref ref="DEBUG_ASYNC"/>-->
<appender-ref ref="WARN_ASYNC"/>
<appender-ref ref="INFO_ASYNC"/>
<appender-ref ref="ERROR_ASYNC"/>
<!-- <appender-ref ref="INFO_FILE"/>-->
<!-- <appender-ref ref="ERROR_FILE"/>-->
</root>
</springProfile>
</configuration>
以上是关于spring boot 性能测试工具汇总logback异步日志分析的主要内容,如果未能解决你的问题,请参考以下文章
spring boot 性能测试工具汇总logback异步日志分析
spring boot 性能测试工具汇总logback异步日志分析