Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Introduction

img

Fuzzing Test๋ฅผ ํ•˜๊ณ ์‹ถ์€๊ฐ€์š”? ์•„๋‹ˆ๋ฉด ์„œ๋ฒ„์˜ ๋ถ€ํ•˜๋ฅผ ํ…Œ์ŠคํŠธํ•˜๊ณ ์‹ถ์€๊ฐ€์š”? ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•ด์„œ ํ•œ๋ˆˆ์— ๋ณด๊ณ ์‹ถ์€๊ฐ€์š”?

์ด๋ฅผ ์œ„ํ•œ HTTP Benchmark Tool์ธ gotybench๋ฅผ ์„ค๊ณ„ํ–ˆ์Šต๋‹ˆ๋‹ค!

  • gotybench ๋Š” ์ž๋™์œผ๋กœ json object๋ฅผ ๋žœ๋คํ•˜๊ฒŒ ์ƒ์„ฑํ•˜์—ฌ HTTP.post ํ•˜๋Š” HTTP Benchmark Tool์ž…๋‹ˆ๋‹ค.

    github link : https://github.com/ghkdqhrbals/gotybench

  • gotybench๋Š” ๋‹ค์Œ์„ ๋ชฉํ‘œ๋กœ ์„ค๊ณ„ ๋ฐ ์ œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  1. ํ…Œ์ŠคํŠธ ๋™์‹œ์„ฑ ๋ณด์žฅ : goroutine ๊ฒฝ๋Ÿ‰ ๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์˜€์œผ๋ฉฐ, ์ฑ„๋„์„ ํ†ตํ•ด ํ†ต์‹ ํ•˜๋„๋ก ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ net/http ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋•Œ๋ฌธ์— ์š”์ฒญ/์‘๋‹ต์€ Blocking ์œผ๋กœ ์ง„ํ–‰๋˜๋ฉฐ ๋‚˜๋จธ์ง€ ์ฒ˜๋ฆฌ๋Š” ์ฑ„๋„์„ ํ†ตํ•ด ๋น„๋™๊ธฐ๋กœ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค. ๋งŽ์€ ์ˆ˜์˜ ์Šค๋ ˆ๋“œ๋ฅผ ๋Œ๋ฆฌ๊ธฐ์— Thread-safe ํ•˜๊ฒŒ ์„ค๊ณ„ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ HandleResponse๋ฅผ ๋‹จ์ผ ์Šค๋ ˆ๋“œ๋กœ ๋Œ๋ฆฌ๊ณ , ์ฑ„๋„์„ ํ†ตํ•ด ๋‹ค๋ฅธ ์Šค๋ ˆ๋“œ๋กœ๋ถ€ํ„ฐ์˜ ์‘๋‹ต์„ ๊ฐ€์ ธ์™€์„œ ์Šค๋ ˆ๋“œ stack ์—์„œ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค๊ณ„ํ•˜์˜€์Šต๋‹ˆ๋‹ค!
  2. ๋‹ค์ด๋‚˜๋ฏน Structure ์„ ํ†ตํ•œ Fuzzed Json ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ : ์‚ฌ์šฉ์ž๊ฐ€ key์™€ value type๋“ค๋งŒ ์„ค์ •ํ•ด์ฃผ๋ฉด ์ž๋™์œผ๋กœ ๋žœ๋คํ•œ json ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก ์ œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
    • ex) โ€œgotybench -j [userId,string,userAge,int]โ€ : userId์˜ value๋ฅผ ๋žœ๋คํ•œ string์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ userAge์˜ value๋ฅผ ๋žœ๋คํ•œ int๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
  3. ๋ฒค์น˜๋งˆํฌ ๋กœ๊ทธ ์„œ๋ฒ„ ๊ฐœ์„ค : ์‘๋‹ต RTT๋ฅผ ์‹œ๊ฐ„ ์‹œ๋ฆฌ์ฆˆ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” ๊ทธ๋ž˜ํ”„ ๋ฐ ๊ธฐํƒ€ ์ •๋ณด๋“ค์„ ์ €์žฅํ•˜๋Š” ๋กœ์ปฌ์„œ๋ฒ„๋ฅผ ์˜คํ”ˆํ–ˆ์Šต๋‹ˆ๋‹ค. (Open Port :8022)

Options

OptionDetail
-c๋™์‹œ์ฒ˜๋ฆฌ๊ฐ€๋Šฅํ•œ ์Šค๋ ˆ๋“œ ๊ฐœ์ˆ˜๋ฅผ ํ•ด๋‹น ์˜ต์…˜์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
-h์˜ต์…˜๋“ค์˜ ์„ค๋ช…์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
-jํ•ต์‹ฌ์ ์ธ Fuzzing ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
json object๋ฅผ ํ•ด๋‹น ์˜ต์…˜์œผ๋กœ key/type์„ ์„ค์ •ํ•˜๋ฉด, ๋žœ๋คํ•œ value์˜ json obejct๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
Fuzzing์ด ์ง€์›๋˜๋Š” type ์€ 4๊ฐ€์ง€๋กœ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.
int, float, string, boolean
Usage Example
ex) -j "[userId,string,userAge,int]"
-rHTTP POST request ๊ฐœ์ˆ˜๋ฅผ ํ•ด๋‹น ์˜ต์…˜์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
-t๋ฒค์น˜๋งˆํฌ ํด๋ผ์ด์–ธํŠธ์˜ network connection ์˜ timeout์„ ํ•ด๋‹น ์˜ต์…˜์œผ๋กœ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
-u์š”์ฒญํ•˜๋Š” URL์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
-s๋กœ๊น…๋œ ์ด์ „ ๋ฒค์น˜๋งˆํฌ ๋ฐ์ดํ„ฐ ๋ฐ ๊ทธ๋ž˜ํ”„๋“ค์„ ์„œ๋ฒ„์— ๋„์›๋‹ˆ๋‹ค.

์ด์ค‘ ํŠนํžˆ -j ์˜ต์…˜์€ Dynamic Struct๋ฅผ ์ฐจ์šฉํ•จ์œผ๋กœ์จ, ์˜ค๋ธŒ์ ํŠธ์˜ private ํ•„๋“œ๋Š” ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ๊ฐ’์— ๋”ฐ๋ผ ๊ตฌ์กฐ๊ฐ€ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค!

Before we started, we need to get โ€ฆ

  1. run go get github.com/fatih/color for coloring your terminal
  2. run go get -v github.com/gosuri/uilive for updating process
  3. run go get -u github.com/go-echarts/go-echarts/v2/... to see graph with responses in timeseries.
  4. run go get github.com/ompluscator/dynamic-struct to dynamically add field of json structs.

Usage

  1. run go run main.go in your terminal and see options

    Alloc = 0 MiB	TotalAlloc = 0 MiB	Sys = 8 MiB	NumGC = 0
        Properties
        - Max parallelism : 8
    Usage of /var/folders/h0/_d_zrr0j57x8wmknjb1r6hfm0000gn/T/go-build3252492082/b001/exe/main:
    -c int
            ์Šค๋ ˆ๋“œ ๊ฐœ์ˆ˜ (default 100)
    -j string
            Json "[KEY1,TYPE1,KEY2,TYPE2,...]" 
    -r int
            ์š”์ฒญ ๊ฐœ์ˆ˜ (default 10000)
    -t int
            ์š”์ฒญ ํƒ€์ž„์•„์›ƒ(second) (default 30)
    -u string
            URL
    -s Opening Log Server
    
  2. choose your options and run

Example

$ go run main.go -j "[userId,string,userPw,string,mail,string,userName,string]" -r 10000 -c 1000 -u http://127.0.0.1:8080/auth/user

 [Properties]
- Max parallelism : 8
- Request url : http://127.0.0.1:8080/auth/user
- The number of HTTP Requests : 10000
- The number of threads : 100
Listening server's response .. (10000/10000)

 [Results]
---------------------------------------------------------
| Response Status 	| Count 	| Percent 	|
| 200 			| 10000/10000 	| 100.0%	|
---------------------------------------------------------
- Average response time 	: 110.66 ms
- Max response time     	: 770.32 ms
- Min response time     	: 21.46 ms

 [Memory Usage]
- Heap size = 2 MB
- Cumulative Heap size = 161 MB
- All goroutine size = 22 MB
- GC cycle ํšŸ์ˆ˜ = 48

Finished! ( Total Elapsed Time : 11.4659 seconds ) 
Now you can see response time series graph in local machine => http://localhost:8022 

Results

๋ฒค์น˜๋งˆํฌ ๊ฒฐ๊ณผ์™€ ์‹œ๊ฐ„์— ๋”ฐ๋ฅธ ์‘๋‹ต RTT ๊ทธ๋ž˜ํ”„ ํ™•์ธ

img