Code Monkey home page Code Monkey logo

gotybench's Introduction

Introduction

  • GotyBench was designed for testing server load with multiple current threads

Currently we service only for HTTP Post request! Later we will add Get/Put Methods

Goal of GotyBench

  1. Testing with multiple concurrency : Developed with goroutine lightweight multi-threaded, set to communicate through channels.
  2. Automatically generate fuzzed json object : It is designed to automatically create a random json object when the user sets only the key and value type.
    • ex) "gotybench -j [userId,string,userAge,int]" : Set the value of userId to a random string. Also set the value of userAge to a random int.
  3. Log server : By -s option, we can check all benchmark logs(http://localhost:8022)

Options

Option Detail
-c The number of concurrent thread
-h See all options
-j Generate fuzzed json object
If you set the key/type of the json object with the corresponding option, a json object with a random value is created.
Four types of fuzzing are supported as follows.
int, float, string, boolean
Usage Example
ex) -j "[userId,string,userAge,int]"
-r The number of HTTP Post request
-t The timeout of the network connection of the benchmark client
-u Request URL
-s Access log server
-i Add additional information

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
  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

Benchmark Results

img

Response RTT graph over time

img

Log Server

img

gotybench's People

Contributors

ghkdqhrbals avatar ghkdqhrbals2 avatar

Watchers

 avatar

gotybench's Issues

EOF error when listening HTTP response.

Solved

Go by default will send requests with the header Connection: Keep-Alive and persist connections for re-use. The problem that I ran into is that the server is responding with Connection: Keep-Alive in the response header and then immediately closing the connection.

As a little background as to how go implements connections in this case (you can look at the full code in net/http/transport.go). There are two goroutines, one responsible for writing and one responsible for reading (readLoop and writeLoop) In most circumstances readLoop will detect a close on the socket, and close down the connection. The problem here occurs when you initiate another request before the readLoop actually detects the close, and the EOF that it reads get interpreted as an error for that new request rather than a close that occurred prior to the request.

Solved by setting request.Close as True will prevent from being re-used!

client := &http.Client{}
req, err := http.NewRequest(method, url, httpBody)

// NOTE this !!
req.Close = true

req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth("user", "pass")
resp, err := client.Do(req)
if err != nil {
    // whatever
}
defer resp.Body.Close()

response, err = ioutil.ReadAll(resp.Body)
if err != nil {
    // Whatever
}

Given that this is the case the reason why sleeping in between requests works is that it gives readLoop time to detect the close on the connection before your new request and shut it down, so that your new request will initiate a new connection. (And the reason why it would intermittently fail is because there is some amount code running between your requests and depending of scheduling of goroutines, sometimes the EOF will be properly handled before your next request, sometimes not). And the req.Close = true, solution works because it prevents the connection from being re-used.

https://stackoverflow.com/questions/17714494/golang-http-request-results-in-eof-errors-when-making-multiple-requests-successi

Bump into "socket: too many open files" error

When I send multiple request throw my server with gotybench, I bump into error below.

First error : socket: too many open files

gyuminhwangbo@Gyuminui-MacBookPro testing % go run main.go -j "[userId,string,userPw,string,mail,string,userName,string]" -r 10000 -t 1000 -u http://127.0.0.1:8080/auth/user
	Request url: http://127.0.0.1:8080/auth/user
	The number of HTTP Requests: 10000
	The number of threads: 1000
	Proceeding! Please wait until getting all the responses
ERROR MESSAGE: Post "http://127.0.0.1:8080/auth/user": dial tcp 127.0.0.1:8080: socket: too many open files
ERROR MESSAGE: Post "http://127.0.0.1:8080/auth/user": dial tcp 127.0.0.1:8080: socket: too many open files
ERROR MESSAGE: Post "http://127.0.0.1:8080/auth/user": dial tcp 127.0.0.1:8080: socket: too many open files
ERROR MESSAGE: Post "http://127.0.0.1:8080/auth/user": dial tcp 127.0.0.1:8080: socket: too many open files

I think the file descriptors size is the main reason for this error.

To overcome this error, I use ulimit -n 2048 to resize my file descriptors(Which is originally 256).

After I type ulimit -n 2048 and re-run testing program, again, error comes.

Second error : read: connection reset by peer

gyuminhwangbo@Gyuminui-MacBookPro testing % go run main.go -j "[userId,string,userPw,string,mail,string,userName,string]" -r 10000 -t 1000 -u http://127.0.0.1:8080/auth/user
	Request url: http://127.0.0.1:8080/auth/user
	The number of HTTP Requests: 10000
	The number of threads: 1000
	Proceeding! Please wait until getting all the responses
ERROR MESSAGE: Post "http://127.0.0.1:8080/auth/user": read tcp 127.0.0.1:57615->127.0.0.1:8080: read: connection reset by peer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.