|
|
|
|
|
by peterwaller
3995 days ago
|
|
Semaphore, I'm suggesting: Block on N-Semaphore, with timeout
Do timeout upload
Replace N-Semaphore
If you don't always replace the semaphore, that's a bug.Queue: I'm just comparing to what the article does. It already has contention on a queue (the chan), it's just the chan-chan-Worker rather than chan-Job. In practice, go channels happily handle millions of messages contending to multiple workers just fine. Consider this test example where you aren't even actually burning any CPU to perform the work: package main
func main() {
q := make(chan int)
for i := 0; i < 10; i++ {
go func() {
for x := range q {
x = x * 10
}
}()
}
for i := 0; i < 1000000; i++ {
q <- i
}
}
On my laptop, it runs in 0.333s single core, and it's slightly slower when you set GOMAXPROCS > 1. But not much slower, the total runtime goes to 0.4-0.5s or so. (Measured with go 1.4). As soon as you do any actual work with the messages you are passing around, the overhead of locking will be lost in the noise. |
|