Jmeter 压测接口返回大量数据时吞吐量上不去问题记录

1. 背景介绍        

        近期需要对外部提供一个批量查询接口,接口逻辑并不复杂,只是返回的数据有点多。分页查询,最大查询100个单子,分页单页最大值没有限制,那么,极端情况下,就是一次查询100个单子,每个单子 6 种节点,每一个节点可以保存最大 10 张图片地址信息,单次查询最多返回 6K 条记录,大概72K。

        由于是对外接口,必须要做压测,使用的工具是 jmeter,压测过程遇到了问题,解决过程中国走了不少弯路,所以,做下记录,也希望能帮到有同样问题的小伙伴。

2. 问题描述

压测执行脚本报错信息:

org.apache.http.ConnectionClosedException: Premature end of chunk coded message body: closing chunk expected
	at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:263)
	at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:222)
	at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:183)
	at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:135)
	at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:148)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.readResponse(HTTPSamplerBase.java:1936)
	at org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl.readResponse(HTTPAbstractImpl.java:476)
	at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:673)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:66)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1296)
	at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1285)
	at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638)
	at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
	at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
	at java.lang.Thread.run(Thread.java:750)

显然,这是被压测接口返回数据量过大导致的。

查看压测的聚合报告,吞吐量很低,发送速率很低,并发量上不来。

3. 解决方案

压缩接口响应信息

3.1 请求头添加参数

Accept-Encoding:gzip, deflate

3.2 springboot服务需要开启压缩

server: 
  port: 8080
  compression:
    enabled: true
    mime-types: application/json,application/xml,text/html,text/xml,text/plain
    min-response-size: 2048
    compression-level: 6

4. 尾记

问题解决,吞吐量飙升

你可能感兴趣的:(jmeter)