2018-12-21 20:09
浏览 96


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?

图片转代码服务由CSDN问答提供 功能建议

我正在用golang编写低延迟网络,高吞吐量服务器。 它在主goroutine中具有接受器(接受传入连接)。 它将传入的连接传递给'n'个工作程序goroutine。

在这种情况下,为了不丢失连接,我希望接受器goroutine优先于其他goroutine,以便赢得连接 不会被丢弃。 或者,至少该接受者goroutine不应被其他工作程序goroutine赶走。


  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douwa6220 2018-12-30 22:29

    I have created threadpools on golang. This should allow easily one to prioritize certain goroutines over others.


    打赏 评论
  • doucan4873 2018-12-22 16:58

    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.

    打赏 评论

相关推荐 更多相似问题