- 浏览: 2537815 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Gatling Version 2.1.7
Gatling only have JSON, CSV, JDBC and some other support. So I wrote the XML support myself.
1 Setup the Gatling Project
plugins.sbt will enable all the plugins
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.1.7")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
build.properties SBT version is update to date
sbt.version=0.13.8
.sbtopts to make the Memory Ok for Large Testing Data File
-J-Xmx1G
-J-XX:+UseConcMarkSweepGC
-J-XX:+CMSClassUnloadingEnabled
-J-Xss2M -Duser.timezone=GMT
Copy and use the default application.con, gatling.conf, logback.xml.
My base class to Prepare the Perf Env in PerformanceTesterEnvironment.scala
package com.sillycat.performance.base
import com.typesafe.config.ConfigFactory
trait PerformanceTesterEnvironment {
val config = ConfigFactory.load
val env = "env." + config.getString("build.env")
private def path(s: String*) = s.mkString(".")
def envStr(s: String): String = {
path(env, s)
}
val rampSeconds = 1
val rampNumOfUsers = config.getInt(envStr("ramp.user.num"))
val requestsPerUser = config.getInt(envStr("requests.per.user"))
val classifierHost = config.getString(envStr("classifier.host"))
}
A typical GET JSON API Simulation, ClassifierGetIndustrySimulation.scala
package com.sillycat.performance.classifier
import com.sillycat.performance.base.PerformanceTesterEnvironment
import com.sillycat.performance.feeder.CustomerFeederSupport
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class ClassifierGetIndustrySimulation extends Simulation with PerformanceTesterEnvironment with CustomerFeederSupport{
val httpConf = http
.baseURL(classifierHost)
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val headers =
Map("Accept" -> "application/json, text/javascript, */*; q=0.01",
"Keep-Alive" -> "180",
"X-Requested-With" -> "XMLHttpRequest",
"Content-type" -> "application/json")
//val jobTitleDescJSONFeed = jsonFile("job.title.desc.json").random
val jobTitleDescXMLFeed = xmlFile("job.title.desc.xml.small").random
val classifyJob2Industry = exec(http("classifyJob2Industry")
.get("/industry")
.headers(headers)
.queryParamMap(Map("title"->"${title}","description" -> "${description}", "format" -> "json"))
.check(status.is(200))
.check(bodyString.exists))
val multiScn = scenario("Classify Industry")
.repeat(requestsPerUser){ feed(jobTitleDescXMLFeed).exec(classifyJob2Industry) }
setUp(
multiScn.inject(rampUsers(rampNumOfUsers) over (1 seconds))
).protocols(httpConf)
}
2 Add Support to XML for Gatling
package com.sillycat.performance.feeder
import io.gatling.core.config.Resource
import io.gatling.core.feeder._
import io.gatling.core.validation.{Failure, Success, Validation}
trait CustomerFeederSupport {
def xmlFile(fileName: String): RecordSeqFeederBuilder[Any] = xmlFile(Resource.feeder(fileName))
def xmlFile(resource: Validation[Resource]): RecordSeqFeederBuilder[Any] =
feederBuilder(resource)(XMLFeederFileParser.parse)
def feederBuilder[T](resource: Validation[Resource])(recordParser: Resource => IndexedSeq[Record[T]]): RecordSeqFeederBuilder[T] =
resource match {
case Success(res) => RecordSeqFeederBuilder(recordParser(res))
case Failure(message) => throw new IllegalArgumentException(s"Could not locate feeder file; $message")
}
}
package com.sillycat.performance.feeder
import java.io.InputStream
import java.net.URL
import io.gatling.core.feeder.Record
import scala.collection._
import io.gatling.core.config.Resource
import io.gatling.core.util.IO._
import scala.xml.{NodeSeq, XML}
object XMLFeederFileParser {
def parse(resource: Resource): IndexedSeq[Record[Any]] =
withCloseable(resource.inputStream) { is =>
stream(is).toVector
}
def url(url: String): IndexedSeq[Record[Any]] =
withCloseable(new URL(url).openStream) { is =>
stream(is).toVector
}
def stream(is: InputStream): Iterator[Record[Any]] = {
val xml = scala.xml.XML.load(is)
(xml \ "JOB").iterator.collect {
case job:NodeSeq => {
Map("title" -> (job \\ "TITLE").text, "description" -> (job \\ "DESC").text).toMap
}
case _ => {
throw new IllegalArgumentException("Root element of XML feeder file isn't an array")
}
}
}
}
Tips
1 Codes to find the mismatched Tag in XML
package com.sillycat.performance
import scala.io.Source
/**
* Created by carl on 12/2/15.
*/
object MainTest extends App{
println("start calculating...")
var line_num = 0
var flag = 0
for(line <- Source.fromFile("/Users/carl/company/code/api-performance/user-files/data/classify.industry.xml.large").getLines()){
line_num = line_num + 1
if(line.contains("<JOB ")){
flag = flag + 1
}
if(line.contains("</JOB>")){
//println(line)
flag = flag - 1
}
if(flag > 1){
println(line_num + " " + flag)
flag = 0
}
}
}
2 XML Validation Error
Exception:
org.xml.sax.SAXParseException; lineNumber: 136589; columnNumber: 10; The content of elements must consist of well-formed character data or markup.
Exception
org.xml.sax.SAXParseException; lineNumber: 263; columnNumber: 49; The entity name must immediately follow the '&' in the entity reference.
Solution:
sublime - [Goto] - [Goto Line]
https://support.microsoft.com/en-us/kb/308060
Find the line number, lookup the special characters mapping, change < to < or > to >
3 Unicode Validation Error
Exception
org.xml.sax.SAXParseException; lineNumber: 1051001; columnNumber: 532; An invalid XML character (Unicode: 0x19) was found in the element content of the document.
Solution:
Right now, I just delete that.
4 HTTP Length Issue
Exception
org.jboss.netty.handler.codec.frame.TooLongFrameException: An HTTP line is larger than 4096 bytes.
at org.jboss.netty.handler.codec.http.HttpMessageDecoder.readLine(HttpMessageDecoder.java:670) ~[io.netty.netty-3.10.4.Final.jar:na]
at org.jboss.netty.handler.codec.http.HttpMessageDecoder.decode(HttpMessageDecoder.java:184) ~[io.netty.netty-3.10.4.Final.jar:na]
at org.jboss.netty.handler.codec.http.HttpMessageDecoder.decode(HttpMessageDecoder.java:102) ~[io.netty.netty-3.10.4.Final.jar:na]
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:500) ~[io.netty.netty-3.10.4.Final.jar:na]
Solution:
We should use POST via form data instead for large length of params.
References:
http://gatling.io/docs/2.1.6/extensions/sbt_plugin.html
https://github.com/gatling/gatling-sbt-plugin-demo
Gatling only have JSON, CSV, JDBC and some other support. So I wrote the XML support myself.
1 Setup the Gatling Project
plugins.sbt will enable all the plugins
addSbtPlugin("io.gatling" % "gatling-sbt" % "2.1.7")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
build.properties SBT version is update to date
sbt.version=0.13.8
.sbtopts to make the Memory Ok for Large Testing Data File
-J-Xmx1G
-J-XX:+UseConcMarkSweepGC
-J-XX:+CMSClassUnloadingEnabled
-J-Xss2M -Duser.timezone=GMT
Copy and use the default application.con, gatling.conf, logback.xml.
My base class to Prepare the Perf Env in PerformanceTesterEnvironment.scala
package com.sillycat.performance.base
import com.typesafe.config.ConfigFactory
trait PerformanceTesterEnvironment {
val config = ConfigFactory.load
val env = "env." + config.getString("build.env")
private def path(s: String*) = s.mkString(".")
def envStr(s: String): String = {
path(env, s)
}
val rampSeconds = 1
val rampNumOfUsers = config.getInt(envStr("ramp.user.num"))
val requestsPerUser = config.getInt(envStr("requests.per.user"))
val classifierHost = config.getString(envStr("classifier.host"))
}
A typical GET JSON API Simulation, ClassifierGetIndustrySimulation.scala
package com.sillycat.performance.classifier
import com.sillycat.performance.base.PerformanceTesterEnvironment
import com.sillycat.performance.feeder.CustomerFeederSupport
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class ClassifierGetIndustrySimulation extends Simulation with PerformanceTesterEnvironment with CustomerFeederSupport{
val httpConf = http
.baseURL(classifierHost)
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
.doNotTrackHeader("1")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")
val headers =
Map("Accept" -> "application/json, text/javascript, */*; q=0.01",
"Keep-Alive" -> "180",
"X-Requested-With" -> "XMLHttpRequest",
"Content-type" -> "application/json")
//val jobTitleDescJSONFeed = jsonFile("job.title.desc.json").random
val jobTitleDescXMLFeed = xmlFile("job.title.desc.xml.small").random
val classifyJob2Industry = exec(http("classifyJob2Industry")
.get("/industry")
.headers(headers)
.queryParamMap(Map("title"->"${title}","description" -> "${description}", "format" -> "json"))
.check(status.is(200))
.check(bodyString.exists))
val multiScn = scenario("Classify Industry")
.repeat(requestsPerUser){ feed(jobTitleDescXMLFeed).exec(classifyJob2Industry) }
setUp(
multiScn.inject(rampUsers(rampNumOfUsers) over (1 seconds))
).protocols(httpConf)
}
2 Add Support to XML for Gatling
package com.sillycat.performance.feeder
import io.gatling.core.config.Resource
import io.gatling.core.feeder._
import io.gatling.core.validation.{Failure, Success, Validation}
trait CustomerFeederSupport {
def xmlFile(fileName: String): RecordSeqFeederBuilder[Any] = xmlFile(Resource.feeder(fileName))
def xmlFile(resource: Validation[Resource]): RecordSeqFeederBuilder[Any] =
feederBuilder(resource)(XMLFeederFileParser.parse)
def feederBuilder[T](resource: Validation[Resource])(recordParser: Resource => IndexedSeq[Record[T]]): RecordSeqFeederBuilder[T] =
resource match {
case Success(res) => RecordSeqFeederBuilder(recordParser(res))
case Failure(message) => throw new IllegalArgumentException(s"Could not locate feeder file; $message")
}
}
package com.sillycat.performance.feeder
import java.io.InputStream
import java.net.URL
import io.gatling.core.feeder.Record
import scala.collection._
import io.gatling.core.config.Resource
import io.gatling.core.util.IO._
import scala.xml.{NodeSeq, XML}
object XMLFeederFileParser {
def parse(resource: Resource): IndexedSeq[Record[Any]] =
withCloseable(resource.inputStream) { is =>
stream(is).toVector
}
def url(url: String): IndexedSeq[Record[Any]] =
withCloseable(new URL(url).openStream) { is =>
stream(is).toVector
}
def stream(is: InputStream): Iterator[Record[Any]] = {
val xml = scala.xml.XML.load(is)
(xml \ "JOB").iterator.collect {
case job:NodeSeq => {
Map("title" -> (job \\ "TITLE").text, "description" -> (job \\ "DESC").text).toMap
}
case _ => {
throw new IllegalArgumentException("Root element of XML feeder file isn't an array")
}
}
}
}
Tips
1 Codes to find the mismatched Tag in XML
package com.sillycat.performance
import scala.io.Source
/**
* Created by carl on 12/2/15.
*/
object MainTest extends App{
println("start calculating...")
var line_num = 0
var flag = 0
for(line <- Source.fromFile("/Users/carl/company/code/api-performance/user-files/data/classify.industry.xml.large").getLines()){
line_num = line_num + 1
if(line.contains("<JOB ")){
flag = flag + 1
}
if(line.contains("</JOB>")){
//println(line)
flag = flag - 1
}
if(flag > 1){
println(line_num + " " + flag)
flag = 0
}
}
}
2 XML Validation Error
Exception:
org.xml.sax.SAXParseException; lineNumber: 136589; columnNumber: 10; The content of elements must consist of well-formed character data or markup.
Exception
org.xml.sax.SAXParseException; lineNumber: 263; columnNumber: 49; The entity name must immediately follow the '&' in the entity reference.
Solution:
sublime - [Goto] - [Goto Line]
https://support.microsoft.com/en-us/kb/308060
Find the line number, lookup the special characters mapping, change < to < or > to >
3 Unicode Validation Error
Exception
org.xml.sax.SAXParseException; lineNumber: 1051001; columnNumber: 532; An invalid XML character (Unicode: 0x19) was found in the element content of the document.
Solution:
Right now, I just delete that.
4 HTTP Length Issue
Exception
org.jboss.netty.handler.codec.frame.TooLongFrameException: An HTTP line is larger than 4096 bytes.
at org.jboss.netty.handler.codec.http.HttpMessageDecoder.readLine(HttpMessageDecoder.java:670) ~[io.netty.netty-3.10.4.Final.jar:na]
at org.jboss.netty.handler.codec.http.HttpMessageDecoder.decode(HttpMessageDecoder.java:184) ~[io.netty.netty-3.10.4.Final.jar:na]
at org.jboss.netty.handler.codec.http.HttpMessageDecoder.decode(HttpMessageDecoder.java:102) ~[io.netty.netty-3.10.4.Final.jar:na]
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:500) ~[io.netty.netty-3.10.4.Final.jar:na]
Solution:
We should use POST via form data instead for large length of params.
References:
http://gatling.io/docs/2.1.6/extensions/sbt_plugin.html
https://github.com/gatling/gatling-sbt-plugin-demo
发表评论
-
Stop Update Here
2020-04-28 09:00 310I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 465NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 361Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 362Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 327Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 417Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 428Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 364Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 444VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 375Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 462NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 413Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 330Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 240GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 443GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 320GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 306Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 284Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 302Serverless with NodeJS and Tenc ...
相关推荐
Gatling 2.1.7 是一款强大的性能测试工具,主要应用于评估和优化软件系统的负载和并发能力。这款工具以其高效、易用和灵活的特性在IT行业中广受青睐。Gatling 的核心设计理念是让性能测试变得简单,使得开发者和测试...
Gatling是一款强大的性能测试工具,尤其适用于Web应用的负载和压力测试。它的设计目标是提供一个易用、灵活且可扩展的平台,让开发者和性能工程师可以快速地编写和执行性能测试场景。Gatling 2.3.0是这个工具的一个...
标题中的"Gatling的非官方Dubbo压测插件基于Gatling2.3.1"揭示了这个项目是为Gatling扩展的一个专用于Dubbo服务压力测试的组件,而Gatling版本号为2.3.1。Gatling是一款高性能、可扩展的负载测试工具,它允许开发者...
Gatling 3.0.0 是一个强大的性能测试工具,专为现代Web应用程序设计,以确保它们在高负载下能够稳定运行。Gatling以其高效、易用和可扩展性而闻名,使得开发者和测试人员能够快速创建、执行和分析性能测试场景。 ...
Gatling 3.0.2 是一款高性能的负载测试工具,专为现代Web应用程序设计,以帮助开发者和性能工程师评估和优化系统在高负载条件下的表现。Gatling以其高效、可扩展性和易于使用的特性而闻名,使得性能测试能够集成到...
Gatling是一款强大的开源性能测试工具,主要用于模拟用户负载,以评估和优化应用程序的性能。在版本3.1.2中,它提供了许多先进的特性和改进,使得性能测试变得更加高效和直观。以下是对这个版本的一些关键知识点的...
1.gatling和其他压力工具相比有个好处是放在同一内网环境下linux服务器上,这样避免其他压力使用办公机使用共有网络,网络情况对压力测试的影响。 2 生成比较详细的压力测试报告。 3 能够更灵活的编写压力脚本。 ...
《gatling-charts-highcharts-2.0.0-M2-bundle:探索新兴的Scala性能测试工具》 Gatling是一款备受推崇的性能测试工具,尤其在开发和运维领域中,它以其高效、易用的特点赢得了广大用户的青睐。这款工具的独特之处...
Gatling是一款基于Scala 开发的高性能服务器性能测试工具,它主要用于对服务器进行负载等测试,并分析和测量服务器的各种性能指标。Gatling主要用于测量基于HTTP的服务器,比如Web应用程序,RESTful服务等,除此之外...
基于moto 开源的java测试架构 gatling 实现的测试用例书写方式
Gatling是一款高性能、开源的负载测试工具,专为现代Web应用程序设计。它的核心特性在于能够模拟大量用户并发访问,以评估系统在高负载下的性能、稳定性以及资源消耗情况。Gatling-Charts-Highcharts-Bundle是...
Gatling的设计理念是易于使用、可扩展且具有高度的可读性,使得性能测试能够集成到开发流程中,成为持续集成的一部分。 在"1.5.4版的gatling"中,我们可以关注以下几个关键知识点: 1. **Gatling架构**:Gatling的...
《Gatling实用技术——高性能轻量级压力测试工具》 Gatling是一款高效、轻量级的压力测试工具,尤其适合具有编程基础的开发人员使用。它的设计基于Scala语言和Akka框架,采用非阻塞异步编程模型,确保了高效率和强...
Gatling是一款新兴的性能测试工具,它以其高效、灵活和易于使用的特点在IT行业中逐渐崭露头角。这款工具的独特之处在于它使用了强大的Scala编程语言来编写测试脚本,使得测试逻辑可以更加清晰和可扩展。Scala是Java...
Gatling is a highly capable load testing tool. It is designed for ease of use, maintainability and high performance.
id 'io.gatling.gradle' version '3.5.0' } ``` 然后,你可以配置插件的属性,例如Gatling测试运行的配置、报告目录等: ```groovy gatling { simulationsFolder = 'src/test/gatling' resultsFolder = 'build/...
这通常包括定义插件的groupId、artifactId、version以及任何其他必要的配置参数,比如Gatling的执行目录和报告输出位置。 2. **脚本编写**: 使用Gatling的DSL编写性能测试脚本,这些脚本定义了模拟用户的行为,如...
id 'io.gatling.gradle' version '4.2.4' // 使用当前版本的Gatling插件 } repositories { mavenCentral() // 配置仓库以获取Gatling依赖 } dependencies { testImplementation 'io.gatling:gatling-app:3.7.3'...