scala - 加特林。连接异常 : connection timed out:

标签 scala testing intellij-idea load gatling

我是 gatling 的新手,现在正在其网站 computer-database.gatling.io 上试用 Gatling。

一切正常,几天后我将在工作中对我的项目进行负载测试,但有一个问题, 我的网站每秒需要 2000 个用户(正如我在其他资源上看到的那样,对于 gatling 来说似乎没什么大不了的)

我有这个简单的代码:我想在 300 秒内加载 250 个用户/管理员,现在是问题和问题(请帮我解决这个问题) 当我启动这个脚本时:

package load

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.core.structure.ChainBuilder
import io.gatling.jdbc.Predef.jdbcFeeder
import scala.util.Random
import scala.concurrent.duration._

class TestOvo extends Simulation {
 val httpProtocol = http
 .baseURL("http://computer-database.gatling.io")
 .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
 .acceptEncodingHeader("gzip, deflate")
 .acceptLanguageHeader("en-US,en;q=0.8")
 .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")

 val headers_0 = Map("Upgrade-Insecure-Requests" -> "1")

 val headers_10 = Map(
 "Origin" -> "http://computer-database.gatling.io",
 "Upgrade-Insecure-Requests" -> "1")

 object Search {
 val search = exec(http("request_0")
 .get("/")
 .headers(headers_0))
 .pause(1)
 .exec(http("request_1")
 .get("/computers?f=macbook")
 .headers(headers_0))
 .pause(2)
 .exec(http("request_2")
 .get("/computers/89")
 .headers(headers_0))
 .pause(2)
 .exec(http("request_3")
 .get("/")
 .headers(headers_0))
 .pause(2)
 }
 object Browse {
 val browse = exec(http("request_4")
 .get("/computers?p=1")
 .headers(headers_0))
 .pause(1)
 .exec(http("request_5")
 .get("/computers?p=2")
 .headers(headers_0))
 .pause(1)
 .exec(http("request_6")
 .get("/computers?p=3")
 .headers(headers_0))
 .pause(2)
 .exec(http("request_7")
 .get("/computers?p=4")
 .headers(headers_0)
 .resources(http("request_8")
 .get("/computers?p=5")
 .headers(headers_0)))
 .pause(1)
 }

 object Edit {
 val edit = exec(http("request_9")
 .get("/computers/new")
 .headers(headers_0))
 .pause(1)
 .exec(http("request_10")
 .post("/computers")
 .headers(headers_10)
 .formParam("name", "VoxooBox")
 .formParam("introduced", "12.11.2017")
 .formParam("discontinued", "")
 .formParam("company", "16")
 .check(status.is(400)))
 .pause(1)
 .exec(http("request_11")
 .post("/computers")
 .headers(headers_10)
 .formParam("name", "VoxooBox")
 .formParam("introduced", "2017.08.17")
 .formParam("discontinued", "")
 .formParam("company", "16")
 .check(status.is(400)))
 .pause(1)
 .exec(http("request_12")
 .post("/computers")
 .headers(headers_10)
 .formParam("name", "VoxooBox")
 .formParam("introduced", "2017-08-17")
 .formParam("discontinued", "")
 .formParam("company", "16"))
 }

 val users = scenario("Users").exec(Search.search, Browse.browse);
 val admins = scenario("Admins").exec(Search.search, Browse.browse, Edit.edit);

 setUp(
 users.inject(constantUsersPerSec(200) during (300 seconds)),
 admins.inject(constantUsersPerSec(50) during (300 seconds))
 ).protocols(httpProtocol)

}

它最大程度地反射(reflect)了用户:

================================================================================
2017-10-17 14:47:20                                          25s elapsed
---- Requests ------------------------------------------------------------------ 

> Global                                                   (OK=15950  KO=0     ) 

> request_0                                                (OK=5046   KO=0     ) 

> request_0 Redirect 1                                     (OK=3829   KO=0     ) 

> request_1                                                (OK=2582   KO=0     ) 

> request_2                                                (OK=1589   KO=0     ) 

> request_3                                                (OK=1249   KO=0     ) 

> request_3 Redirect 1                                     (OK=897    KO=0     ) 

> request_4                                                (OK=423    KO=0     ) 

> request_5                                                (OK=224    KO=0     ) 

> request_6                                                (OK=88     KO=0     ) 

> request_7                                                (OK=17     KO=0     ) 

> request_8                                                (OK=6      KO=0     )

---- Users ---------------------------------------------------------------------
[------                                                                    ]  0%

          waiting: 55156  / active: 4842   / done:2     
---- Admins --------------------------------------------------------------------
[------                                                                    ]  0%

          waiting: 13788  / active: 1212   / done:0     
================================================================================

14:47:21.107 [WARN ] i.g.h.a.ResponseProcessor - Request 'request_5' failed: j.n.ConnectException: connection timed out: computer-database.gatling.io/35.158.229.206:80

然后出现这些错误:

[警告] i.g.h.a.ResponseProcessor - 请求“request_4”失败:j.n.ConnectException:连接超时:computer-database.gatling.io/35.158.229.206:80 13:31:12.407 [警告] i.g.h.a.ResponseProcessor - 请求“request_4”失败:j.n.ConnectException:无法打开套接字。

在 gatling.conf 中我发现了这些行:

ahc {
  #keepAlive = true                                # Allow pooling HTTP connections (keep-alive header automatically added)
  #connectTimeout = 10000                          # Timeout when establishing a connection
  #handshakeTimeout = 10000                        # Timeout when performing TLS hashshake
  #pooledConnectionIdleTimeout = 60000             # Timeout when a connection stays unused in the pool
  #readTimeout = 60000                             # Timeout when a used connection stays idle
  #maxRetry = 2                                    # Number of times that a request should be tried again
  #requestTimeout = 60000                          # Timeout of the requests
  #acceptAnyCertificate = true                     # When set to true, doesn't validate SSL certificates
  #httpClientCodecMaxInitialLineLength = 4096      # Maximum length of the initial line of the response (e.g. "HTTP/1.0 200 OK")
  #httpClientCodecMaxHeaderSize = 8192             # Maximum size, in bytes, of each request's headers
  #httpClientCodecMaxChunkSize = 8192              # Maximum length of the content or each chunk
  #webSocketMaxFrameSize = 10240000                # Maximum frame payload size

我想这可能与我的问题有关,或者我做错了什么?这是我的附带问题还是他们的网站无法接受?

以及为什么在我启动时

users.inject(constantUsersPerSec(200) during (300 seconds)),
 admins.inject(constantUsersPerSec(50) during (300 seconds))

在终端中是

waiting: 55156  / active: 4842   / done:2
 waiting: 13788  / active: 1212   / done:0 

这么多?它是如何计算的?或者为什么,请向我解释一下。 谢谢。

我的电脑: 苹果系统 版本:10.12.6 ( 处理器:2.6 GHz 英特尔酷睿 i5 内存:8 GB 1600 MHz DDR3

最佳答案

constantUsersPerSec() 是关于您注入(inject)的用户数,而不是总用户数。

constantUsersPerSec(200) during (300 seconds),即 60k 用户。因此,这与 waiting: 55156/active: 4842/done:2= 60k users 匹配。

我认为您真正想要的是使用以下策略注入(inject)用户:rampUsers(10) over (300 seconds)

关于scala - 加特林。连接异常 : connection timed out:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46789808/

相关文章:

scala - 使用响应式(Reactive) mongo 驱动程序时,控制台 Scala 应用程序不会停止

java - 如果类名可用于导入,Intellij idea 不会给我创建类意图操作

scala - 如何让IntelliJ识别Scala脚本中的导入?

java - 如何让 IntelliJ 为非基于 ruby​​ 的项目加载我的 .rvmrc?

Scala:伴随对象和 "new"关键字

scala - 在 EMR Notebooks 中添加外部 jar

scala - sbt:模块之间的循环依赖?

django - 何时以及为什么我应该在 Django 网络应用程序中从功能性 Selenium 测试切换到单元测试?

php - 设置可访问性在使用它时不会使私有(private)属性可访问它 mock

java - Apache Camel 测试在使用camel-archetype-blueprint 创建的项目中失败