Reputation: 2906
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?
Upvotes: 3
Views: 7260
Reputation: 2906
I have created threadpools on golang. This should allow easily one to prioritize certain goroutines over others.
https://github.com/vijayviji/executor
Upvotes: 2
Reputation: 2197
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.
Upvotes: -2