| 1 | # Influx Stress tool -> `v2` |
| 2 | |
| 3 | The design of the new stress tool was designed to: |
| 4 | * have higher potential write throughput than previous version |
| 5 | * have more schema expressibility for testing different load profiles and professional services |
| 6 | * have more granular reporting to be better able to draw conclusions from tests |
| 7 | |
| 8 | In service of these requirements we designed a language that looks a lot like `influxql` to give the new test commands. Instead of a configuration file, the new stress test takes a list of these `Statements`. |
| 9 | |
| 10 | The tool has the following components: |
| 11 | * Parser - parses the configuration file and turns it into an `[]Statement`. All code related to the parser is in `v2/stressql/`. The parser was designed as per @benbjohnson's great article on [parsers in go](https://blog.gopheracademy.com/advent-2014/parsers-lexers/). |
| 12 | * Statements - perform operations on target instance or change test environment. All code related to statements is in `v2/statement/`. The following are the available statements: |
| 13 | - `EXEC` - Still a TODO, planned to run outside scripts from the config file. |
| 14 | - `GO` - Prepend to an `INSERT` or `QUERY` statement to run concurrently. |
| 15 | - `INFLUXQL` - All valid `influxql` will be passed directly to the targeted instance. Useful for setting up complex downsampling environments or just your testing environment. |
| 16 | - `INSERT` - Generates points following a template |
| 17 | - `QUERY` - Runs a given query or generates sample queries given a companion `INSERT` statement |
| 18 | - `SET` - Changes the test parameters. Defaults are listed in the `README.md` |
| 19 | - `WAIT` - Required after a `GO` statement. Blocks till all proceeding statements finish. |
| 20 | * Clients - The statement, results and InfluxDB clients. This code lives in `v2/stress_client` |
| 21 | - `StressTest` - The `Statement` client. Also contains the results client. |
| 22 | - `stressClient` - A performant InfluxDB client. Makes `GET /query` and `POST /write` requests. Forwards the results to the results client. |
| 23 | |
| 24 |  |
| 25 | |
| 26 | ### Statements |
| 27 | |
| 28 | `Statement` is an interface defined in `v2/statement/statement.go`: |
| 29 | ```go |
| 30 | type Statement interface { |
| 31 | Run(s *stressClient.StressTest) |
| 32 | Report(s *stressClient.StressTest) string |
| 33 | SetID(s string) |
| 34 | } |
| 35 | ``` |
| 36 | * `Run` prompts the statement to carry out it's instructions. See the run functions of the various statements listed above for more information. |
| 37 | * `Report` retrieves and collates all recorded test data from the reporting InfluxDB instance. |
| 38 | * `SetID` gives the statement an ID. Used in the parser. Each `statementID` is an 8 character random string used for reporting. |
| 39 | |
| 40 | ### `Statement` -> `StressTest` |
| 41 | |
| 42 | `Statement`s send `Package`s (queries or writes to the target database) or `Directives` (for changing test state) through the `StressTest` to the `stressClient` where they are processed. |
| 43 | ```go |
| 44 | // v2/stress_client/package.go |
| 45 | |
| 46 | // T is Query or Write |
| 47 | // StatementID is for reporting |
| 48 | type Package struct { |
| 49 | T Type |
| 50 | Body []byte |
| 51 | StatementID string |
| 52 | Tracer *Tracer |
| 53 | } |
| 54 | |
| 55 | // v2/stress_client/directive.go |
| 56 | |
| 57 | // Property is test state variable to change |
| 58 | // Value is the new value |
| 59 | type Directive struct { |
| 60 | Property string |
| 61 | Value string |
| 62 | Tracer *Tracer |
| 63 | } |
| 64 | ``` |
| 65 | |
| 66 | The `Tracer` on both of these packages contains a `sync.WaitGroup` that prevents `Statement`s from returning before all their operations are finished. This `WaitGroup` is incremented in the `Run()` of the statement and decremented in `*StressTest.resultsListen()` after results are recorded in the database. This is well documented with inline comments. `Tracer`s also carry optional tags for reporting purposes. |
| 67 | |
| 68 | ```go |
| 69 | // v2/stress_client/tracer.go |
| 70 | type Tracer struct { |
| 71 | Tags map[string]string |
| 72 | |
| 73 | sync.WaitGroup |
| 74 | } |
| 75 | ``` |
| 76 | |
| 77 | ### `StressTest` |
| 78 | |
| 79 | The `StressTest` is the client for the statements through the `*StressTest.SendPackage()` and `*StressTest.SendDirective()` functions. It also contains some test state and the `ResultsClient`. |
| 80 | |
| 81 | ```go |
| 82 | type StressTest struct { |
| 83 | TestID string |
| 84 | TestName string |
| 85 | |
| 86 | Precision string |
| 87 | StartDate string |
| 88 | BatchSize int |
| 89 | |
| 90 | sync.WaitGroup |
| 91 | sync.Mutex |
| 92 | |
| 93 | packageChan chan<- Package |
| 94 | directiveChan chan<- Directive |
| 95 | |
| 96 | ResultsChan chan Response |
| 97 | communes map[string]*commune |
| 98 | ResultsClient influx.Client |
| 99 | } |
| 100 | ``` |
| 101 | |
| 102 | ### Reporting Client |
| 103 | |
| 104 | The `ResultsClient` turns raw responses from InfluxDB into properly tagged points containing any relevant information for storage in another InfluxDB instance. The code for creating those points lives in `v2/stress_client/reporting.go` |
| 105 | |
| 106 | ### InfluxDB Instance (reporting) |
| 107 | |
| 108 | This is `localhost:8086` by default. The results are currently stored in the `_stressTest` database. |
| 109 | |
| 110 | ### `stressClient` |
| 111 | |
| 112 | An InfluxDB client designed for speed. `stressClient` also holds most test state. |
| 113 | |
| 114 | ```go |
| 115 | // v2/stress_client/stress_client.go |
| 116 | type stressClient struct { |
| 117 | testID string |
| 118 | |
| 119 | // State for the Stress Test |
| 120 | addresses []string |
| 121 | precision string |
| 122 | startDate string |
| 123 | database string |
| 124 | wdelay string |
| 125 | qdelay string |
| 126 | |
| 127 | // Channels from statements |
| 128 | packageChan <-chan Package |
| 129 | directiveChan <-chan Directive |
| 130 | |
| 131 | // Response channel |
| 132 | responseChan chan<- Response |
| 133 | |
| 134 | // Concurrency utilities |
| 135 | sync.WaitGroup |
| 136 | sync.Mutex |
| 137 | |
| 138 | // Concurrency Limit for Writes and Reads |
| 139 | wconc int |
| 140 | qconc int |
| 141 | |
| 142 | // Manage Read and Write concurrency separately |
| 143 | wc *ConcurrencyLimiter |
| 144 | rc *ConcurrencyLimiter |
| 145 | } |
| 146 | ``` |
| 147 | Code for handling the write path is in `v2/stress_client/stress_client_write.go` while the query path is in `v2/stress_client/stress_client_query.go`. |
| 148 | |
| 149 | ### InfluxDB Instance (stress test target) |
| 150 | |
| 151 | The InfluxDB which is being put under stress. |
| 152 | |
| 153 | ### response data |
| 154 | |
| 155 | `Response`s carry points from `stressClient` to the `ResultsClient`. |
| 156 | |
| 157 | ```go |
| 158 | // v2/stress_client/response.go |
| 159 | type Response struct { |
| 160 | Point *influx.Point |
| 161 | Tracer *Tracer |
| 162 | } |
| 163 | ``` |
| 164 |