| 92 | } |
| 93 | |
| 94 | func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { |
| 95 | var mux sync.Mutex |
| 96 | var successCounter int64 = 0 |
| 97 | var errorCounter int64 = 0 |
| 98 | startTime := time.Now() |
| 99 | tickerCh := time.NewTicker(logFrequency).C |
| 100 | for { |
| 101 | select { |
| 102 | case r := <-resultCh: |
| 103 | mux.Lock() |
| 104 | if r { |
| 105 | successCounter++ |
| 106 | } else { |
| 107 | errorCounter++ |
| 108 | } |
| 109 | mux.Unlock() |
| 110 | case <-tickerCh: |
| 111 | var avg float64 = 0 |
| 112 | if successCounter > 0 { |
| 113 | avg = float64(successCounter) / time.Since(startTime).Seconds() |
| 114 | } |
| 115 | logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) |
| 116 | case <-stopCh: |
| 117 | os.Exit(0) |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | func publish(index int, resultCh chan<- bool, stopCh <-chan struct{}) { |
| 123 | delayCh := time.NewTicker(publishDelay).C |