1. RollingFileAppender
配置:
<appender name="localFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<ImmediateFlush>false</ImmediateFlush>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{32} %L - %msg %n</pattern>
</encoder>
<file>${LOG_HOME}/fileLog.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/fileLog_%d{yyyyMMddHH}_%i.log.zip
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>
测试30s左右,去掉ImmediateFlush, 37s左右
2. 采用异步输出
配置:
<appender name ="asyncFile" class= "ch.qos.logback.classic.AsyncAppender">
<!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
<discardingThreshold >0</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>2048</queueSize>
<includeCallerData>true</includeCallerData>
<!-- 添加附加的appender,最多只能添加一个 -->
<appender-ref ref ="localFile"/>
</appender>
includeCallerData = true: 27s左右
includeCallerData = false: 22s左右
3. 现网测试
不开启Logback, TPS: 3100左右;
未添加includeCallerData=true和ImmediateFlush=false时, TPS只能到500左右,
添加这两个配置后,TPS能到2900左右