我有通过WS的Web服务器Spring Boot + STOMP。 很快,这个微服务将投入生产,我想测量负载下websocket的性能。我想知道我的服务将处理多少用户(并基于该配置自动缩放)
服务是REST API + STOMP主题发布者。 我想写一个场景:
然后,基于统计信息,我将发现有多少用户可以处理我的服务。 目前,我可以生成用户,通过WS进行连接,仅此而已。 如何创建一定数量的用户并创建单个http请求,以触发所有用户都已订阅的STOMP主题上的事件发布?
这是我当前的测试场景。
package computerdatabase
import java.util.concurrent.TimeUnit
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.core.check.Check
import io.gatling.http.Predef._
import io.gatling.http.check.ws.WsTextCheck
import scala.concurrent.duration.{Duration, FiniteDuration}
import scala.util.Random
class TickerSimulation extends Simulation {
val baseUrl = "https://myserverurl.com"
val httpProtocol = http
.baseUrl(baseUrl)
.inferHtmlResources(BlackList(""".*\.js""", """.*\.css""", """.*\.gif""", """.*\.jpeg""", """.*\.jpg""", """.*\.ico""", """.*\.woff""", """.*\.woff2""", """.*\.(t|o)tf""", """.*\.png""", """.*detectportal\.firefox\.com.*"""))
.acceptHeader("*/*")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("de,en-US;q=0.7,en;q=0.3")
.userAgentHeader("Mozilla/5.0 (X11; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0")
def randomServerId(): String = {
val rand = new Random()
(1 to 3).map { _ => rand.nextInt(10).toString }.mkString
}
def randomSessionId(): String = {
Random.alphanumeric.take(8).mkString
}
val feeder = Iterator.continually(Map(
"serverId" -> randomServerId(),
"sessionId" -> randomSessionId()
))
val headers_0 = Map(
"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"DNT" -> "1",
"Pragma" -> "no-cache",
"Content-Type" -> "application/json",
"Upgrade-Insecure-Requests" -> "1",
"Authorization" -> "Basic somebasicauth=")
val answerCheck = ws.checkTextMessage("Connection acknowledge answer")
.check(regex("^a.*"))
val answerEventCheck = ws.checkTextMessage("Game event received")
.check(regex(".*gameEvent.*"))
val scn = scenario("WidgetTicker")
.feed(feeder)
.exec(http("Get game info ")
.get("/api/game/35384")
.headers(headers_0))
.pause(Random.nextInt(10))
.exec(ws("WS connection").connect("ws://myserverurl.com/api/sock/${serverId}/${sessionId}/websocket"))
.pause(1)
.exec(ws("Connect via STOMP")
.sendText("[\"CONNECT\\naccept-version:1.1,1.0\\nheart-beat:10000,10000\\n\\n\\u0000\"]")
.await(60 seconds)(answerCheck)
).pause(3)
.exec(ws("Subscribe")
.sendText("""["SUBSCRIBE\nid:sub-0\ndestination:/topic/game/35384\n\n\u0000"]""")
.await(60 seconds)(answerEventCheck)
)
.pause(3)
.exec(ws("WS close").close)
setUp(scn.inject(
atOnceUsers(1000)
)).protocols(httpProtocol)
}