发布

时间:2018-05-18 10:20:37

标签: python django jmeter django-rest-framework jwt

我正在针对单个EC2实例设置测试。在那个EC2中它只有Django应用程序。它没有S3 / CloundFront或RDS协助它。一切都纯粹在Docker上运行,并且基本设置了内存和CPU。

我的目标是希望看到单一EC2的经验表现。它将帮助我粗略估算生产成本。

你可以跳过这个并跳转到我的问题:
这是我的生产设置
1负载平衡
使用泊坞窗图像的2个节点具有相同的设置 1桶/云端
1 rds

软件:
Django的== 2.0.5
djangorestframework,智威汤逊== 1.11.0
djangorestframework == 3.8.2

工具
JMeter 4.0 r1823414
javac 10.0.1
java 10.0.1 2018-04-17
Java(TM)SE运行时环境18.3(版本10.0.1 + 10)
Java HotSpot(TM)64位服务器VM 18.3(版本10.0.1 + 10,混合模式)

java版“1.8.0_171” Java(TM)SE运行时环境(版本1.8.0_171-b11) Java HotSpot(TM)64位服务器VM(内置25.171-b11,混合模式) javac 1.8.0_171

参数:

线程组
- 线程数:10
- 加速期:1
- 循环计数:1

HTTP标头管理器
- Content-TypeApplication/json
- Authorization: jwt ${token}

HTTP请求
- http
- localhost
- port:8000
- POST
- 路径:/api-token-auth/
- 正文数据:{"username": "myname", "password": "mysecretpassword"}

此时测试很好。一切都是绿色的我可以从token返回Django

问题:

org.apache.http.NoHttpResponseException: localhost:8000 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl$5.doReceiveResponse(HTTPHC4Impl.java:401)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.executeRequest(HTTPHC4Impl.java:842)
at org.apache.jmeter.protocol.http.sampler.HTTPHC4Impl.sample(HTTPHC4Impl.java:581)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:67)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1231)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1220)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253)
at java.lang.Thread.run(Thread.java:748)

附加参数
JSON提取器
- Main sample only
- 创建变量的名称:token
- JSON路径表达式:$.token
- 比赛号码(0为随机):1

HTTP请求
- http
- localhost
- port: 8000
- PATCH
- /api/branches/5/
- 正文数据:{"name": "Bangkok"}

我试过this但是我无法让它发挥作用。这是我的导航栏吧 nav bar jmeter

调试采样器:
Jmeter的token为空

JMeterVariables:
JMeterThread.last_sample_ok=false
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage@79e6c86e
START.HMS=095906
START.MS=1526612346142
START.YMD=20180518
TESTSTART.MS=1526639371341
__jm__Users__idx=0
__jmeter.USER_TOKEN__=Users 1-1
token=
token_matchNr=0

问题:
如何让jmeter抓住jwt令牌并拍摄另一个端点?

UPDATE1:
当我禁用Patch Branch时。 Debug Sampler确实显示token

UPDATE2:
我错误地调用变量。但PATCH问题仍然存在。现在我可以致电token。这是我的request

PATCH http://localhost:8000/api/branches/5/

PATCH data:
{
    "name": "Bangkok"
}


[no cookies]

Request Headers:
Connection: keep-alive
Autorization: jwt eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxMCwidXNlcm5hbWUiOiJ0b255b2QiLCJleHAiOjE1MjY2NzIzOTMsImVtYWlsIjoidG9ueW9kQG1teC5jb20iLCJvcmlnX2lhdCI6MTUyNjY0MzU5M30.mjKJ2sRFx26pyChET1ORzLmv6umL7B1_Sy8wnNJO-iQ
Content-Type: Application/json
Content-Length: 26
Host: localhost:8000
User-Agent: Apache-HttpClient/4.5.5 (Java/10.0.1)

UPDATE3:
问题似乎是jmeter方因为。当我打开后端日志时。 PATCH永远不会到达后端

INFO|18/May/2018 11:52:04|"POST /api-token-auth/ HTTP/1.1" 200 224
INFO|18/May/2018 12:01:35|"POST /api-token-auth/ HTTP/1.1" 200 224

更新:4
找到了线索。这可能是HTTPClient4

的问题

更新:5
尝试模仿原始的java8环境。它提出了同样的问题 https://jmeter.apache.org/download_jmeter.cgi

http://www.jmeter-archive.org/org-apache-http-NoHttpResponseException-td5719349.html

2 个答案:

答案 0 :(得分:1)

因为当您取消选中“使用KeepAlive”时,它会起作用,这意味着Connection很可能因为JMeter默认值不适用于您的用例而变得陈旧。

您需要调整:

  • httpclient4.idletimeout
  • httpclient4.validate_after_inactivity:减少它
  • httpclient4.time_to_live

请参阅:

答案 1 :(得分:0)

oleg对我的问题做了answer。我必须取消选中Use KeepAlive