Image result for gatling.io

Thingsboard và những công nghệ liên quan – Gatling

Sử dụng Gatling.io trong performance test

Sử dụng ngôn ngữ Scala

dòng ngang

Image result for gatling.io

Giới thiệu

Tổng quan về Gatling

Muốn đảm bảo cho service hoạt động tốt thì việc kiểm thử “áp lực” (stress test) là một quy trình không thể thiếu trong performance testing.

Stress test giúp chúng ta phát hiện các nghẽn cổ chai (bottleneck) của hệ thống, qua đó giúp chúng ta tránh khỏi việc service bị ngưng hoạt động một cách đột ngột.

Gatling là một công cụ sử dụng trong stress test. Sử dụng ngôn ngữ scala để phát triển test case, Gatling cung cấp cho người dùng một testing framework có khả năng tạo tải, kiểm thử service và xuất report dạng html.

Chức năng của Gatling

  • Test theo scenario sử dụng scenario script viết bằng scala ( gatling script cực kì dễ viết 😉 )
  • Report kết quả bằng html file với giao diện đẹp và rất dễ nhìn
  • Trang bị sẵn “recorder” giúp các bạn có thể tạo scenario bằng việc “record” lại các thao tác trên browser.

Cài đặt

Để chạy được Gatling.io, ta cần cài đặt môi trường JDK 8 (Java SE Development Kit 8)

*Lưu ý: Gatling.io chỉ tương thích với phiên bản JDK 8

sudo apt install openjdk-8-jdk -y

Tải gói Gatling.io

wget https://repo1.maven.org/maven2/io/gatling/highcharts/gatling-charts-highcharts-bundle/3.1.2/gatling-charts-highcharts-bundle-3.1.2-bundle.zip

Với phiên bản bundle (gatling-charts-highcharts-bundle-3.0.3-bundle.zip) chúng ta chỉ cần giải nén là có thể sử dụng được

Cấu trúc thư mục:

  • bin: Chứa các script thực hiện Gatling và Recorder
  • conf: Chứa cấu hình cho Gatling như Log, Report, ..
  • lib: Chứa thư viên sử dụng bởi Gatling
  • user-files: Chứa dữ liệu người dùng
  • simulations: Chứa các kịch bản test (Scale file).
  • data: Chứa các dữ liệu mẫu (Feeder files)
  • bodies: Chứa template cho Request ảo
  • results: Chứa kết quả sau những lần thực hiện test

Sử dụng

Cấu trúc test case

Một gatling testcase có rất nhiều thành phần tùy vào độ phức tạp của tác vụ. Testcase đơn giản nhất sẽ bao gồm:

  1. Khai báo thư viện
  2. Kịch bản

Chạy kịch bản

Cách 1:

Khởi động Gatling

cd gatling-charts-highcharts-bundle-3.0.3/bin./gatling.sh

Chọn kịch bản vừa quay

GATLING_HOME is set to /home/thanhnb/Bench/gatling-charts-highcharts-bundle-3.0.3

Choose a simulation number:

[0] LandingBench

[1] computerdatabase.AdvancedSimulation01

[2] computerdatabase.BasicSimulation

[3] computerdatabase.advanced.AdvancedSimulationStep01

[4] computerdatabase.advanced.AdvancedSimulationStep02

[5] computerdatabase.advanced.AdvancedSimulationStep03

[6] computerdatabase.advanced.AdvancedSimulationStep04

[7] computerdatabase.advanced.AdvancedSimulationStep05

1 < CHỌN 1 ĐÚNG KỊCH BẢN VỪA QUAY>

Select run description (optional)

<ENTER TẠI ĐÂY>

Simulation RecordedSimulation started…

Kết quả

Reports generated in 0s.Please open the following file: /home/thanhnb/Bench/gatling-charts-highcharts-bundle-3.0.3/results/advancedsimulation01-20190324145718601/index.html

Thay đổi tải mô phỏng

Để thay đổi tải mô phỏng, chúng ta sẽ sửa lại block setup trong script.

Mẫu 1: Thực hiện 1 user đồng thời

setUp(

scn.inject(

atOnceUsers(1)

)

).protocols(httpProtocol)

Mẫu 2: Thực hiện 10 user đồng thời

setUp(

scn.inject(

atOnceUsers(10)

)

).protocols(httpProtocol)

Cách 2:

Vào thư mục gatling:

cd gatling-charts-highcharts-bundle-3.0.3/

Chạy lệnh:

mvn gatling:test

Sử dụng gatling với IDE

Gatling có thể sử dụng với IntelliJ IDE, tạo project sử dụng maven archetype

Ta sẽ được project như hình bên:

0 replies


Leave a Reply

Your email address will not be published.