Pengujian Beban Gatling - Panduan Lengkap. Bagian 1

Artikel ini adalah panduan lengkap, terperinci, dan komprehensif untuk menggunakan Gatling secara efektif untuk pengujian beban. Anda juga dapat melihat tutorial video YouTube Gatling saya di mana saya membahas lebih detail tentang topik ini.





Ringkasan manual

HTTP-, Gatling - ! Gatling. Gatling, .





Gatling? Gatling. :





  • Gatling - , Scala.





  • DSL, Gatling, .





  • (, JMeter), .





  • , .





  • Gatling CI-.





?

, , (performance testing).





- , , , .





, . , . (, , ) .





, :





  • (Load Testing) - ( );





  • - (Stress Testing) - , ยซ ยป (breakpoint).





  • (Soak Testing) - .





Gatling .





, :





  • (Transaction Response Times) - , .





  • (Throughput) - , .





  • (Errors) - , (, -).





Gatling, . Gatling, .





Github.






1. Gatling

- , , JDK8 ( ). , JDK.





Gatling - Gatling Gatling.io. ยซDownload Nowยป, ZIP-:





Unduh Gatling
Download Gatling

. bin. :





  • gatling.bat - Windows





  • gatling.sh - Mac Unix





Gatling :





Pilih Simulasi Gatling untuk dijalankan
Choose Gatling Simulation to run

0, computerdatabase.BasicSimulation



. (run description), , .





Gatling , Gatling .






2. Gatling Recorder

, , , Gatling, , , .





Gatling ( !), IDE .





, Gatling Recorder (user journey).





2.1 HAR- 

Gatling Recorder, , HAR- (Http-) Google Chrome.





Gatling Recorder HTTPS.





HAR-, :





  1. Gatling - , .





  2. Chrome Developer Tools Network.





  3. Clear, , , .





  4. , - , - , . . , Network .





  5. Network ยซSave all as HAR with contentยป



    . - .





  1. bin Gatling ( Gatling ) recorder.sh



    Mac/Unix recorder.bat



    Windows. Gatling Recorder.





  2. Recorder Mode HAR Converter



    .





  3. HAR File HAR-, 5.





  4. , Class Name , , MyComputerTest



    .





  5. Start!





  6. , , , .





Tangkapan layar Gatling Recorder
Gatling Recorder screenshot
  1. , bin Gatling gatling.sh



    gatling.bat



    .   , Gatling , .





, user-files/simulations Gatling. MyComputerTest



, , . - :





import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class MyComputerTest extends Simulation {

	val httpProtocol = http
		.baseUrl("http://computer-database.gatling.io")
		.inferHtmlResources()
		.userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36")

	val headers_0 = Map(
		"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
		"Accept-Encoding" -> "gzip, deflate",
		"Accept-Language" -> "en-GB,en-US;q=0.9,en;q=0.8",
		"Upgrade-Insecure-Requests" -> "1")



	val scn = scenario("MyComputerTest")
		.exec(http("request_0")
			.get("/computers")
			.headers(headers_0))
		.pause(9)
		.exec(http("request_1")
			.get("/computers?f=amstrad")
			.headers(headers_0))
		.pause(4)
		.exec(http("request_2")
			.get("/assets/stylesheets/bootstrap.min.css")
			.resources(http("request_3")
			.get("/assets/stylesheets/main.css")))

	setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

      
      



Gatling. - , , , .






3. Gatling

, , , Gatling ( ), . , , IDE:





3.1 IDE Gatling

Gatling , ( ) IDE. , Scala. Scala JVM, IDE, JVM, .





:





  • Eclipse, Java IDE. Eclipse , Gatling Eclipse, .





  • , () , - Visual Studio Code VS Code. IDE . Gatling VS Code .





  • , , - IntelliJ IDEA. Scala. Gatling.





, IDE, , :





3.2 Gatling

, Gatling zip- ( ). , - Gatling. . , :





  • - Scala Build Tool, SBT. Gatling SBT. SBT Gatling, , .





  • , , - Maven. Java, , - Maven. Maven Gatling, Maven Gatling, .





IntelliJ Idea Maven .





3.3 Gatling Maven

:





mvn archetype:generate
      
      



, :





Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):
      
      



gatling



.





:





1: remote -> io.gatling.highcharts:gatling-highcharts-maven-archetype (gatling-highcharts-maven-archetype)
      
      



1



Gatling. :





Pilih Versi Gatling
Choose Gatling Version

35



, 3.3.1 .





groupId com.gatlingTest



.





artifactId myGatlingTest



.





version ENTER, 1.0-SNAPSHOT



.





package ENTER , com.gatlingTest



.





Y



, , Maven .





, , - IDE. IntelliJ.





IntelliJ Import Project.





Impor proyek IntelliJ Gatling
Import IntelliJ Gatling project

, , pom.xml



. open, Intellij IDE .





, , Project Directory src>test>scala. Engine.scala. No Scala SDK in module



. , Setup Scala SDK:





Impor Scala SDK di IntelliJ
Import Scala SDK in IntelliJ

, Scala :





Versi Scala di IntelliJ
Scala versions in IntelliJ

, , Create, 2.12 download:





: Scala 2.12 IntelliJ - 2.13, , Gatling





Unduh Scala di Intelli
Download Scala in Intelli

, Scala IntelliJ, Scala Scala-lang. Download the Scala binaries, :





Unduh biner Scala dari Scala-lang
Download Scala binaries from Scala-lang

- ZIP-. IntelliJ, Setup Scala SDK, Configure. Add :





Tambahkan biner Scala ke IntelliJ
Add the Scala binaries to IntelliJ

, , lib:





Pilih folder Lib untuk mengimpor Scala Binaries
Select the Lib folder to import Scala Binaries

Add Scala Support Scala, :





Tambahkan Dukungan Scala
Add Scala Support

, scala source root IntelliJ. scala Mark Directory As -> Test Sources Root:





Tandai Sumber Uji sebagai Root di IntelliJ
Mark Test Sources as Root in IntelliJ

src source root:





Tandai Sumber Root
Mark Sources Root

, Engine



Run:





Jalankan Objek Mesin di IntelliJ
Run the Engine Object in IntelliJ

There is no simulation script. Please check that your scripts are in user-files/simulations



. , Gatling.





3.4 Gatling

, Gatling. Gatling.





: Gatling- , ... Gatling, , .





scala New > Scala Package - computerdatabase



. New > Scala Class - BasicSimulation



. :





package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class BasicSimulation extends Simulation {

  val httpProtocol = http
    .baseUrl("http://computer-database.gatling.io") //       URL

    .acceptHeader(
      "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
    ) //   
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .userAgentHeader(
      "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0"
    )

  val scn =
    scenario("Scenario Name") //        
      .exec(
        http("request_1")
          .get("/")
      )
      .pause(7) //  ,  Gatling     

  setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
}

      
      



. Engine Run Engine. Gatling , computerdatabase.BasicSimulation is the only simulation, executing it



. Enter, .





Gatling Maven . mvn gatling:test



. Gatling Maven Gatling.





Gatling ! , . Gatling, API- - !






" " - LoadRunner Virtual User Generator, web-, . web-.





-








All Articles