|
| 1 | +# Resiliency Testing using ToxiProxy |
| 2 | + |
| 3 | +This is [Go](https://golang.org) lang project that demonstrates how to use [Toxiproxy](https://toxiproxy.io) from Shopify for chaos and resiliency testing. |
| 4 | + |
| 5 | +## Setup |
| 6 | + * Clone the repository |
| 7 | + * Create database in PostgreSQL like ` psql -h localhost -U postgres -w -c "create database proxytest;"` |
| 8 | + * Edit `cmd/proxytest/main.go` for database connection and setting up proxy, |
| 9 | + |
| 10 | + ``` |
| 11 | + func main() { |
| 12 | + dbConnString := "postgres://postgres:@localhost:32777/proxytest?sslmode=disable" |
| 13 | + |
| 14 | + tproxy, err := setup.AddPGProxy("[::]:32777", "localhost:5432") |
| 15 | + |
| 16 | + ``` |
| 17 | + (Todo: for me to move these settings to configuration). Update `dbConnString` as well as ports in call to `AddPGProxy` as per your environment |
| 18 | + |
| 19 | + * Project consists of REST API that reads from PostgreSQL database. It has two end-points, |
| 20 | + * /api/cities - This end-point returns list of cities in JSON format but without any Toxics |
| 21 | + * /api/cities/latency - This end-point returns list of cities in JSON format with induced latency. One can specify latency in miliseconds using `/api/cities/latency?delay=200` (default is 100). |
| 22 | + |
| 23 | + * Download Toxiproxy server for your OS from [here](https://toxiproxy.io). |
| 24 | + * Run the server |
| 25 | + * Run Benchmark tests `go test -v -bench=. -benchtime=10s ./...` from root folder of repo. |
| 26 | + |
| 27 | + * or Use benchmarking tools like Rakyll's excellent [hey](https://github.com/rakyll/hey) to generate traffic and observe impact. |
| 28 | + * Run Web server using `go run cmd/proxytest/main.go` |
| 29 | + * Run hey, `hey http://localhost:8080/api/cities` |
| 30 | + * On my Laptop, 4-core I5, 8GB RAM with Both API + Postgresql + Toxiproxy running, it shows below, |
| 31 | + * Without Latency, |
| 32 | + |
| 33 | + ``` |
| 34 | + Summary: |
| 35 | + Total: 23.5590 secs |
| 36 | + Slowest: 7.2657 secs |
| 37 | + Fastest: 0.9188 secs |
| 38 | + Average: 5.4242 secs |
| 39 | + Requests/sec: 8.4893 |
| 40 | +
|
| 41 | +
|
| 42 | + Response time histogram: |
| 43 | + 0.919 [1] |■ |
| 44 | + 1.554 [7] |■■■■ |
| 45 | + 2.188 [2] |■ |
| 46 | + 2.823 [9] |■■■■■ |
| 47 | + 3.458 [3] |■■ |
| 48 | + 4.092 [2] |■ |
| 49 | + 4.727 [13] |■■■■■■■■ |
| 50 | + 5.362 [22] |■■■■■■■■■■■■■ |
| 51 | + 5.996 [69] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ |
| 52 | + 6.631 [49] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■ |
| 53 | + 7.266 [23] |■■■■■■■■■■■■■ |
| 54 | +
|
| 55 | +
|
| 56 | + Latency distribution: |
| 57 | + 10% in 3.2869 secs |
| 58 | + 25% in 5.2367 secs |
| 59 | + 50% in 5.7531 secs |
| 60 | + 75% in 6.2558 secs |
| 61 | + 90% in 6.6610 secs |
| 62 | + 95% in 6.9587 secs |
| 63 | + 99% in 7.1657 secs |
| 64 | +
|
| 65 | + Details (average, fastest, slowest): |
| 66 | + DNS+dialup: 0.0096 secs, 0.9188 secs, 7.2657 secs |
| 67 | + DNS-lookup: 0.0077 secs, 0.0000 secs, 0.0450 secs |
| 68 | + req write: 0.0003 secs, 0.0000 secs, 0.0023 secs |
| 69 | + resp wait: 5.3926 secs, 0.8664 secs, 7.2541 secs |
| 70 | + resp read: 0.0216 secs, 0.0050 secs, 0.0900 secs |
| 71 | +
|
| 72 | + Status code distribution: |
| 73 | + [200] 200 responses |
| 74 | +
|
| 75 | + ``` |
| 76 | +
|
| 77 | + * With Latency of 300 Ms, |
| 78 | +
|
| 79 | + ``` |
| 80 | + Summary: |
| 81 | + Total: 23.4831 secs |
| 82 | + Slowest: 8.2054 secs |
| 83 | + Fastest: 2.1162 secs |
| 84 | + Average: 5.3499 secs |
| 85 | + Requests/sec: 8.5168 |
| 86 | +
|
| 87 | +
|
| 88 | + Response time histogram: |
| 89 | + 2.116 [1] |■ |
| 90 | + 2.725 [20] |■■■■■■■■■■■■■■■■■■■ |
| 91 | + 3.334 [1] |■ |
| 92 | + 3.943 [6] |■■■■■■ |
| 93 | + 4.552 [23] |■■■■■■■■■■■■■■■■■■■■■ |
| 94 | + 5.161 [28] |■■■■■■■■■■■■■■■■■■■■■■■■■■ |
| 95 | + 5.770 [35] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ |
| 96 | + 6.379 [43] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ |
| 97 | + 6.988 [23] |■■■■■■■■■■■■■■■■■■■■■ |
| 98 | + 7.597 [9] |■■■■■■■■ |
| 99 | + 8.205 [11] |■■■■■■■■■■ |
| 100 | +
|
| 101 | +
|
| 102 | + Latency distribution: |
| 103 | + 10% in 2.6683 secs |
| 104 | + 25% in 4.4909 secs |
| 105 | + 50% in 5.5572 secs |
| 106 | + 75% in 6.3346 secs |
| 107 | + 90% in 7.1538 secs |
| 108 | + 95% in 7.6392 secs |
| 109 | + 99% in 8.1987 secs |
| 110 | +
|
| 111 | + Details (average, fastest, slowest): |
| 112 | + DNS+dialup: 0.0096 secs, 2.1162 secs, 8.2054 secs |
| 113 | + DNS-lookup: 0.0063 secs, 0.0000 secs, 0.0326 secs |
| 114 | + req write: 0.0011 secs, 0.0000 secs, 0.0131 secs |
| 115 | + resp wait: 5.2940 secs, 1.7847 secs, 8.1922 secs |
| 116 | + resp read: 0.0451 secs, 0.0050 secs, 0.4180 secs |
| 117 | +
|
| 118 | + Status code distribution: |
| 119 | + [200] 200 responses |
| 120 | +
|
| 121 | + ``` |
| 122 | +
|
| 123 | +
|
| 124 | +## Todo |
| 125 | + * Implement other toxics(like down, bandwidth, timeouts) provided by Toxiproxy. |
0 commit comments