记一次压测

前言

先说一下测试的背景,本次测试是关于一个回调接口,没有业务逻辑,期望系统的处理能力可以达到3000TPS。

大概的业务调用关系是这样的:

image.png

问题

在压测开始,没觉得的会有什么问题,首先脚本很简单,一个post接口,没有进行任何的参数化,只是单纯的向服务器发送请求,且接口没有任何返回值。

  • 接口的压测策略,设置的梯度加压,最大并发用户就只有4个
  • 这个是TPS,从下图可以看出,是很有规律的波动
image.png
  • 这个是响应时间,同TPS一样,很有规律的波动
image.png
  • 下图为聚合报告,由此可以看此,99%的响应时间均小于4ms,最大响应时间为3s多。
image.png

根据以上结果,开始就觉得,是不是服务器的问题,但是监控服务器,cpu、内存、io等都很正常,这时又把目光转向压力机和jmeter本身。

这时,就想到是不是压力机本身出现了瓶颈,虽说考虑到其配置觉得可能性比较小(32核64G),通过win任务管理器查看机器的性能数据如下:

  • 压力机:

可以看到,在压测时,机器用开启了1130个线程数,71个进程数

image.png

根据测试结果,响应时间99%小于4ms,于是就设置了一个超时时间,设置为30ms,再次执行脚本。这时,得到的结果可以看到 大多数为链接失败,但有两种链接失败的情况,于是上网查找以下问题可能的原因:

image.png

最后,看到一个教程说,需要设置以下Advanced-Implementation,选择“java”。于是乎,就尝试的设置一下,结果,后续请求一切正常。

image.png

Abvanced:

java、HttpClint4

jmeter官方文档给出的说明我复制了下来:

HTTP Request
This sampler lets you send an HTTP/HTTPS request to a web server.
It also lets you control whether or not JMeter parses HTML files for images 
and other embedded resources and sends HTTP requests to retrieve them. 
The following types of embedded resource are retrieved:
      images
      applets
      stylesheets (CSS) and resources referenced from those files
      external scripts
      frames, iframes
      background images (body, table, TD, TR)
      background sound
      
      
The default parser is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser.
This can be changed by using the property "htmlparser.className" - see jmeter.properties for details.

If you are going to send multiple requests to the same web server, 
consider using an HTTP Request Defaults Configuration Element so you do not have to enter the same information for each HTTP Request.

Or, instead of manually adding HTTP Requests, you may want to use JMeter's HTTP(S) Test Script Recorder to create them.
This can save you time if you have a lot of HTTP requests or requests with many parameters.

There are two different test elements used to define the samplers:

AJP/1.3 Sampler
    uses the Tomcat mod_jk protocol (allows testing of Tomcat in AJP mode without needing Apache httpd) 
  The AJP Sampler does not support multiple file upload; only the first file will be used.
HTTP Request
    this has an implementation drop-down box, which selects the HTTP protocol implementation to be used:
Java
    uses the HTTP implementation provided by the JVM. 
  This has some limitations in comparison with the HttpClient implementations - see below.
HTTPClient4
    uses Apache HttpComponents HttpClient 4.x.
Blank Value
    does not set implementation on HTTP Samplers, 
  so relies on HTTP Request Defaults if present or on jmeter.httpsampler property defined in jmeter.properties

The Java HTTP implementation has some limitations:

There is no control over how connections are re-used. When a connection is released by JMeter, it may or may not be re-used by the same thread.
The API is best suited to single-threaded usage - various settings are defined via system properties, and therefore apply to all connections.
No support of Kerberos authentication
It does not support client based certificate testing with Keystore Config.
Better control of Retry mechanism
It does not support virtual hosts.
It supports only the following methods: GET, POST, HEAD, OPTIONS, PUT, DELETE and TRACE
Better control on DNS Caching with DNS Cache Manager

个人理解--待完善

关于此处,如何去理解?

问题2

在压测过程中,当线程数和请求数比较少的时候,一切正常,但是随着线程数增加,请求量上升,就开始一直报错。
线程数比较少时,正常;
当线程说多时,报错信息如下:

2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Unexpected end of file from server
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Unexpected end of file from server
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.net.SocketException: Socket closed
2020-02-18 14:06:01,584 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.net.SocketException: Socket closed

解决思路

在网上查询一下报错信息,是说重定向的次数被限制了,但因为自己压测的接口没有重定向,而且前期一直正常,到后面才出现这个问题,这不科学。所以就继续寻找问题。
首先,因为我压测的链路是这样的

SLB --- nginx--kong---docker swarm --具体应用

这时,尝试性的跳过SLB ,直接到nginx,发现压测结果一切正常,这时可以初步判断问题在SLB。

经过查询,发现是因为SLB有一个防攻击的配置,将后面大量的请求,当作了攻击,所以才不行。

至此,问题解决。


以下是重定向请求的一些响应信息,仅作为记录:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<h1>302 Found</h1>
<p>The requested resource resides temporarily under a different URI.</p>
<hr/>Powered by Tengine</body>
</html>
HTTP/1.1 302 Found
Server: Tengine
Date: Tue, 18 Feb 2020 10:14:20 GMT
Content-Type: text/html
Content-Length: 258
Connection: keep-alive
Set-Cookie: acw_sc__v1=5e4bb8fc37967fa0c859c94a7f9dafd851d8bb95;path=/;Max-Age=1800
cache-control: no-cache, no-store
Pragma: no-cache
Set-Cookie: acw_tc=784c10e715820208607852086e610bc1cb505dd898c94daf023389aca8c4d8;path=/;HttpOnly;Max-Age=2678401
Location: /application-center/api/v1/xxx/xxx/20000001103
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343