I have created threadpools on golang. This should allow easily one to prioritize certain goroutines over others.
I'm writing a low latency network, high throughput server in golang. It has acceptor in the main goroutine (which accepts incoming connections). And it passes the incoming connections to 'n' number of worker goroutines.
In this case, to not drop connections, I want the acceptor goroutine to be prioritized over other goroutines so that connections won't be dropped. Or atleast this acceptor goroutine should not get evicted by other worker goroutines.
How can I ensure this?
- 点赞 评论 复制链接分享
If you prioritize accepting connections over "doing the work", consider what happens over time. You will create a backlog of work, while accepting more and more connections, bringing even more work to be done. This just makes the load on your server higher.
Instead, focus on writing your worker code to be very efficient, so that the work will be completed quickly, freeing up resources to handle new connections.
If you are concerned about your server being unable to handle the workload, you should think about rate-limiting your clients.点赞 评论 复制链接分享