Closed equals215 closed 4 months ago
This is 11pm type of code, it's either genius tier or complete forgettable trash code
I'm really not sure about the Gosched, I understand the idea behind this but it makes the code way less predictable. What's the real advantage here? The predictability cost seems high.
In what way does it make the code less predictable? It quite literally the same as a time.Sleep() that would run until all the other routines worked for a cycle. This is really common and help for better resources sharing between goroutines.
How a time out would be needed? There is either something in the channel or there is not, it's not a waiting question
How a time out would be needed? There is either something in the channel or there is not, it's not a waiting question
My bad for forgetting chan receive in select is not blocking! And after more reading, I think the Gosched part is a fine idea. LGTM!
Handover Process and Use of runtime.Gosched()
Handover Process
We've implemented a new "handover" mechanism to optimize item processing in our high-performance crawling system. Here's how it works:
This approach prioritizes immediate processing when workers are available, minimizing latency and reducing pressure on the main queue.
Use of
runtime.Gosched()
We've introduced
runtime.Gosched()
in our worker loop for scenarios when no work is immediately available. Here's why:runtime.Gosched()
yields the processor, allowing other goroutines to run.time.Sleep()
.It's important to note that
runtime.Gosched()
doesn't block the goroutine; it simply puts it at the back of the run queue. This means our workers remain highly responsive to new work while being more cooperative with other system components.