Author Topic: Simulation setup ว่าด้วยการ injection user setUp  (Read 9115 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2145
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Simulation setup ว่าด้วยการ injection user setUp
« on: กุมภาพันธ์ 09, 2016, 04:40:35 PM »
http://gatling.io/docs/2.0.0/general/simulation_setup.html

Simulation setup
This is where you define the load you want to inject to your server.

You can configure assertions and protocols with these two methods:

assertions: set assertions on the simulation, see the dedicated section here
protocols: set protocols definitions, see the dedicated section here.
Injection
The definition of the injection profile of users is done with the inject method. This method takes as argument a sequence of injection steps that will be processed sequentially. E.g.:

setUp(
  scn.inject(
    nothingFor(4 seconds), // 1
    atOnceUsers(10), // 2
    rampUsers(10) over(5 seconds), // 3
    constantUsersPerSec(20) during(15 seconds), // 4
    constantUsersPerSec(20) during(15 seconds) randomized, // 5
    rampUsersPerSec(10) to(20) during(10 minutes), // 6
    rampUsersPerSec(10) to(20) during(10 minutes) randomized, // 7
    splitUsers(1000) into(rampUsers(10) over(10 seconds)) separatedBy(10 seconds), // 8
    splitUsers(1000) into(rampUsers(10) over(10 seconds)) separatedBy(atOnceUsers(30)), // 9
    heavisideUsers(1000) over(20 seconds) // 10
    ).protocols(httpConf)
  )
The building blocks for profile injection the way you want are:

nothingFor(duration): Pause for a given duration.
atOnceUsers(nbUsers): Injects a given number of users at once.
rampUsers(nbUsers) over(duration): Injects a given number of users with a linear ramp over a given duration.
constantUsersPerSec(rate) during(duration): Injects users at a constant rate, defined in users per second, during a given duration. Users will be injected at regular intervals.
constantUsersPerSec(rate) during(duration) randomized: Injects users at a constant rate, defined in users per second, during a given duration. Users will be injected at randomized intervals.
rampUsersPerSec(rate1) to (rate2) during(duration): Injects users from starting rate to target rate, defined in users per second, during a given duration. Users will be injected at regular intervals.
rampUsersPerSec(rate1) to(rate2) during(duration) randomized: Injects users from starting rate to target rate, defined in users per second, during a given duration. Users will be injected at randomized intervals.
heavisideUsers(nbUsers) over(duration): Injects a given number of users following a smooth approximation of the heaviside step function stretched to a given duration.
splitUsers(nbUsers) into(injectionStep) separatedBy(duration): Repeatedly execute the defined injection step separated by a pause of the given duration until reaching nbUsers, the total number of users to inject.
splitUsers(nbUsers) into(injectionStep1) separatedBy(injectionStep2): Repeatedly execute the first defined injection step (injectionStep1) separated by the execution of the second injection step (injectionStep2) until reaching nbUsers, the total number of users to inject.
Global Pause configuration
The pauses can be configure on Simulation with a bunch of methods:

disablePauses: disable the pauses for the simulation
constantPauses: the pause durations are precisely those filled in the pause(duration) element.
exponentialPauses: the pause durations are on average those filled in the pause(duration) element and follow an exponential distribution.
customPauses(custom: Expression[Long]): the pause duration is computed by the provided Expression[Long]. In this case the filled duration is bypassed.
uniformPauses(plusOrMinus: Double) and uniformPauses(plusOrMinus: Duration): the pause durations are on average those filled in the pause(duration) element and follow an uniform distribution.
Note
Pause definition can also be configured at scenario level.

Throttling
If you want to reason in terms of request per second and not in terms of users, Gatling support throttling with the throttle method, e.g.:

setUp(...).throttle(
  reachRps(100) in (10 seconds),
  holdFor(1 minute),
  jumpToRps(50),
  holdFor(2 hours)
)
This simulation will reach 100 req/s with a ramp of 10 seconds, then hold this throughput for 1 minute, jump to 50 req/s and finally hold this throughput for 2 hours.

The building block for the throttling are:

reachRps(target) in (duration): target a throughput with a ramp over a given duration.
jumpToRps(target): jump immediately to a given targeted throughput.
holdFor(duration): hold the current throughput for a given duration.
Note
Defining throttling doesn’t prevent you from injecting users at the scenario level. Throttling tries to ensure a targeted throughput on the simulation level with the given scenarios and their injection profiles.
Throttling can also be configured at scenario level.
Maximum duration
Finally, you can configure the maximum duration of your simulation with the method maxDuration. It is useful if you need to bound the duration of your simulation when you can’t predict it.

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2145
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Simulation setup ว่าด้วยการ injection user setUp
« Reply #1 on: กุมภาพันธ์ 09, 2016, 06:04:42 PM »
มี trick นิดหนึ่งในกรณีถ้าต้องการยิง user ละ 2 connection ถ้าผมมี userid 4 จะเป็นทั้งหมด 8 connection

จะมีวิธีดังนี้ครับผม

เริ่มแรก generate userid ก่อน

$for i in {1..4}; do echo "abc$i"; done
abc1
abc2
abc3
abc4

แล้วใส่ลงใน csv file
USERID
abc1
abc2
abc3
abc4
abc1
abc2
abc3
abc4

ในส่วนของ feed user login จะเป็น
.feed(csv("userid.csv"))

ส่วนการ inject จะเป็น
setUp(scn.inject(rampUsers (8) over (10 seconds))).protocols(httpProtocol)

ลองกันดูนะครับผม  ;)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2145
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: Simulation setup ว่าด้วยการ injection user setUp
« Reply #2 on: กุมภาพันธ์ 10, 2016, 11:29:19 AM »
#setUp inject รูปแบบ
setUp(scn.inject(atOnceUsers(1000)) // เป็นการสั่งให้ เริ่มการยิงพร้อมกัน ทุกๆ User เข้าไปที่ app
setUp(scn.inject(rampUsers(1000) over (30 seconds) // เป็นการยิงเข้าไปทีละน้อย จนถึง 1000 user ในระยะเวลา 30 วินาที

If you want to check that all your users responds in less than 3 seconds, one way to ensure this is Gatling's assertions:
แต่ถ้าต้องการเทส เพื่อดู respond time ภายใน 3 วินาที ให้ใช้ลักษณะของ global.respondTime.mac.lessThan แทน ตามด้านล่างนี้
setUp(...).assertions(global.responseTime.max.lessThan(3000))

If this assertion fails, meaning at least one user responded in more than 3 seconds, Gatling will clearly indicate the failure after your simulation is completed.