| 62 | } |
| 63 | |
| 64 | func (wp workerPool) detectWords() int { |
| 65 | var numWordsDetected int |
| 66 | for word := range wp.msgs { |
| 67 | // simulate work |
| 68 | length := time.Duration(rand.Int63n(50)) |
| 69 | time.Sleep(length * time.Millisecond) |
| 70 | // this condition returns words like whale, whaling, whales |
| 71 | if strings.Contains(word, "whal") { |
| 72 | wp.mu.Lock() |
| 73 | numWordsDetected++ |
| 74 | wp.mu.Unlock() |
| 75 | } |
| 76 | } |
| 77 | return numWordsDetected |
| 78 | } |
| 79 | |
| 80 | // export cpu and mem profiles to a file that can be processed by pprof tool |
| 81 | func runPprof(memprofile, cpuprofile string) { |