Implement processing rate limits

This commit is contained in:
2015-10-17 05:33:46 +03:00
parent a9a50522fb
commit 0f4bed32c8
3 changed files with 18 additions and 3 deletions
+1 -3
View File
@@ -20,6 +20,7 @@ func (n *NumberPrinter) Startup() {
})
n.SystemProcess("Random Number Generator", n.generateNumbers)
n.LimitRate(1, 2*time.Second)
}
// Shutdown is empty due to the lack of cleanup.
@@ -33,9 +34,6 @@ func (n *NumberPrinter) generateNumbers() {
// Generate a random number between 1000 and 9999 and print it
num := 1000 + rand.Intn(9000)
n.Process(n.makeActor(num))
// Sleep for a second or less
time.Sleep(time.Duration(rand.Intn(1000)) * time.Millisecond)
}
}
+1
View File
@@ -22,6 +22,7 @@ func (p *PriceConsumer) Startup() {
b.Subscribe("ProductPriceUpdates", func(u PriceUpdate) {
log.Printf("Price for %q is now $%.2f", u.Product, u.Amount)
})
p.LimitRate(1, 500*time.Millisecond)
}
// Shutdown is empty because PriceConsumer requires no cleanup upon exiting.