File: benchmark_test.go

package info (click to toggle)
toxiproxy 2.0.0%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 388 kB
  • ctags: 321
  • sloc: sh: 91; makefile: 59
file content (95 lines) | stat: -rw-r--r-- 2,372 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main

import (
	"io/ioutil"
	"net/http"
	"testing"
)

// Benchmark numbers:
//
// Toxiproxy 1.1
//
// 1x Toxic Types:
//     BenchmarkDirect             3000            588148 ns/op
//     BenchmarkProxy              2000            999949 ns/op
//     BenchmarkDirectSmall        5000            291324 ns/op
//     BenchmarkProxySmall         3000            504501 ns/op
//
// 10x Toxic Types:
//     BenchmarkDirect             3000            599519 ns/op
//     BenchmarkProxy              2000           1044746 ns/op
//     BenchmarkDirectSmall        5000            280713 ns/op
//     BenchmarkProxySmall         3000            574816 ns/op
//
// Toxiproxy 2.0
//
// No Enabled Toxics:
//     BenchmarkDirect             2000            597998 ns/op
//     BenchmarkProxy              2000            964510 ns/op
//     BenchmarkDirectSmall       10000            287448 ns/op
//     BenchmarkProxySmall         5000            560694 ns/op

// Test the backend server directly, use 64k random endpoint
func BenchmarkDirect(b *testing.B) {
	client := http.Client{}
	for i := 0; i < b.N; i++ {
		resp, err := client.Get("http://localhost:20002/test1")
		if err != nil {
			b.Fatal(err)
		}
		_, err = ioutil.ReadAll(resp.Body)
		if err != nil {
			b.Fatal(err)
		}
		resp.Body.Close()
	}
}

// Test the backend through toxiproxy, use 64k random endpoint
func BenchmarkProxy(b *testing.B) {
	client := http.Client{}
	for i := 0; i < b.N; i++ {
		resp, err := client.Get("http://localhost:20000/test1")
		if err != nil {
			b.Fatal(err)
		}
		_, err = ioutil.ReadAll(resp.Body)
		if err != nil {
			b.Fatal(err)
		}
		resp.Body.Close()
	}
}

// Test the backend server directly, use "hello world" endpoint
func BenchmarkDirectSmall(b *testing.B) {
	client := http.Client{}
	for i := 0; i < b.N; i++ {
		resp, err := client.Get("http://localhost:20002/test2")
		if err != nil {
			b.Fatal(err)
		}
		_, err = ioutil.ReadAll(resp.Body)
		if err != nil {
			b.Fatal(err)
		}
		resp.Body.Close()
	}
}

// Test the backend through toxiproxy, use "hello world" endpoint
func BenchmarkProxySmall(b *testing.B) {
	client := http.Client{}
	for i := 0; i < b.N; i++ {
		resp, err := client.Get("http://localhost:20000/test2")
		if err != nil {
			b.Fatal(err)
		}
		_, err = ioutil.ReadAll(resp.Body)
		if err != nil {
			b.Fatal(err)
		}
		resp.Body.Close()
	}
}