Skip to content

Commit

Permalink
small fix to README.md
Browse files Browse the repository at this point in the history
refactor tests to increase coverage
  • Loading branch information
asyronen committed Jun 22, 2020
1 parent 4349b55 commit 0e42f5a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -52,7 +52,7 @@ type RequestHandler interface {
```
for more examples please refer to the examples folder in the codebase.

## running a benchmark
## Running a benchmark
to run a benchmark simply compile the code and run it from the command line. you can pass it the following arguments:
1. concurrency - sets the level of concurrent requests generated by the tool
2. throughput - sets the target throughput the tool will try to reach. setting this target helps prevent coordinated omission which is the biggest advantage of wrk2
Expand All @@ -62,7 +62,7 @@ an example could be:\
`./bench --concurrency=20 --throughput=10000 --duration=20s`\
other flags could be added by using the default flag library and calling `wrk3.DefineBenchmarkFlags()` before calling `flag.Parse()`

## final report
## Final report
at the end of the benchmark a report will be produced to the console, displaying the actual throughput as well as latency distribution.\
an example report of the http benchmark could look as follows:
```text
Expand Down
35 changes: 31 additions & 4 deletions wrk3_test.go
Expand Up @@ -44,7 +44,7 @@ func TestSlowHttpBench(t *testing.T) {
Concurrency: 10,
Throughput: 1000,
Duration: expectedDuration,
SendRequest: createHTTPLoadFunction("http://localhost:8081/", 5*time.Second),
SendRequest: createHTTPLoadHandler("http://localhost:8081/", 5*time.Second),
}.Run()

assert.True(t, benchResult.Throughput < 500, "throughput too high for slow server. actual value %s", benchResult.Throughput)
Expand All @@ -56,23 +56,50 @@ func TestSlowHttpBench(t *testing.T) {
_ = server.Close()
}

func createHTTPLoadFunction(url string, timeout time.Duration) RequestHandler {
type handler struct {
client *http.Client
url string
}

func (h *handler) ExecuteRequest(_ int) error {
resp, err := h.client.Get(h.url)
if resp != nil {
_, _ = io.Copy(ioutil.Discard, resp.Body)
_ = resp.Body.Close()
}

return err
}

func createHTTPLoadHandler(url string, timeout time.Duration) RequestHandler {
return &handler{
url: url,
client: &http.Client{
Transport: &http.Transport{
MaxConnsPerHost: 200,
},
Timeout: timeout,
},
}
}

func createHTTPLoadFunction(url string, timeout time.Duration) RequestFunc {
client := &http.Client{
Transport: &http.Transport{
MaxConnsPerHost: 200,
},
Timeout: timeout,
}

return RequestFunc(func(index int) error {
return func(index int) error {
resp, err := client.Get(url)
if resp != nil {
_, _ = io.Copy(ioutil.Discard, resp.Body)
_ = resp.Body.Close()
}

return err
})
}
}

func createHTTPServer(addr string) *http.Server {
Expand Down

0 comments on commit 0e42f5a

Please sign in to comment.