LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
| 4 |
| 5 // Tests channel performance/scalability in different setups. |
| 6 // chan-ring tests channel scalability in single-producer/single-consumer mode. |
| 7 // A set of goroutines is arranged into "a ring" connected by channels, |
| 8 // a number of small messages is passed through the ring. |
| 9 // There are 4 variations: unbuf/buf10/buf100/buf1000 that relate to |
| 10 // unbuffered channels and buffered channels of size 10/100/1000, respectiv
ely. |
| 11 // Buffered variations are expected to scale rather good. |
| 12 // chan-pc tests channel scalability in multi-producer/multi-consumer mode. |
| 13 // N producer goroutines and N consumer goroutines stress single channel. |
| 14 // There are 4 variations: unbuf/buf10/buf100/buf1000 that relate to |
| 15 // unbuffered channels and buffered channels of size 10/100/1000, respectiv
ely. |
| 16 // work variations execute some amount of local work before/after item prod
uction/consumption. |
| 17 // Is not expected to scale. |
4 | 18 |
5 package main | 19 package main |
6 | 20 |
7 import ( | 21 import ( |
8 "container/vector" | 22 "container/vector" |
9 "runtime" | 23 "runtime" |
10 ) | 24 ) |
11 | 25 |
12 func benchmarkRing(chansize int) { | 26 func benchmarkRing(chansize int) { |
13 procs := runtime.GOMAXPROCS(-1) | 27 procs := runtime.GOMAXPROCS(-1) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 benchmarks.Push(&Benchmark{"chan-pc-buf10-work", func() { | 160 benchmarks.Push(&Benchmark{"chan-pc-buf10-work", func() { |
147 benchmarkPC(10, 100) | 161 benchmarkPC(10, 100) |
148 }}) | 162 }}) |
149 benchmarks.Push(&Benchmark{"chan-pc-buf100-work", func() { | 163 benchmarks.Push(&Benchmark{"chan-pc-buf100-work", func() { |
150 benchmarkPC(100, 100) | 164 benchmarkPC(100, 100) |
151 }}) | 165 }}) |
152 benchmarks.Push(&Benchmark{"chan-pc-buf1000-work", func() { | 166 benchmarks.Push(&Benchmark{"chan-pc-buf1000-work", func() { |
153 benchmarkPC(1000, 100) | 167 benchmarkPC(1000, 100) |
154 }}) | 168 }}) |
155 } | 169 } |
LEFT | RIGHT |