问题描述
这本书和示例表明,在引导服务器时,我们应该使用所谓的boss
组和worker
组:
The book and examples indicates that we should use the so-called boss
group and the worker
group when bootstraping the server:
serverBootstrap.group(bossGroup, workerGroup);
然后,在基于Netty的Vert.x中,我们有:
And then, in the Vert.x that is based on Netty we have:
bootstrap.group(availableWorkers);
这意味着(afaiu)所有工人都将以相同的方式工作,因此没有老板可以只处理传入的联系.
which mean (afaiu) that all workers is going to work the same, so no bosses to handle just the incoming connections.
那是为什么?
推荐答案
在大多数情况下,使用同一组来接受和处理接受的连接的效果很好,因此可以节省一些线程.唯一不希望这样做的时间是,如果接受的连接的处理逻辑会使EventLoops如此繁忙,以致于您不能足够快地接受.因此,最好的方法是在启动时只使用同一组,并在需要时切换到两个.
Most of the times using the same group for accepting and handling the accepted connections is working out quite well and so allows you to save some threads. The only time when you may not want to do this is if the handling logic of the accepted connections will keep the EventLoops so busy that you are not able to accept fast enough. So best is to just use the same group when you start and switch to two if you need it.
这篇关于与老板组或仅与工人EventLoopGroup一起进行Netty引导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!