Giter VIP home page Giter VIP logo

Comments (4)

panjf2000 avatar panjf2000 commented on May 22, 2024

@lonerwolf
现在是用 round-robin 轮询分配的,怎么会导致连接都分配到一个 poller 里?

from gnet.

lonerwolf avatar lonerwolf commented on May 22, 2024

@lonerwolf
现在是用 round-robin 轮询分配的,怎么会导致连接都分配到一个 poller 里?

因为轮询,所有有问题,比如2个EPOLL,进来2个连接,两个都是一个,然后2号EPOLL里的这个连接断开了,他重新连接就到1号上去了,不断累积就不平衡了

from gnet.

panjf2000 avatar panjf2000 commented on May 22, 2024

客户端连接是长连接和短连接混合的时候,Round-Robin 负载均衡的确会出现你说的这种问题,这是算法决定的,所以我建议你复用连接或者用 gnetSO_REUSEPORT 模式,让内核来做负载均衡。

因为 Round-Robin 最好实现也最简洁而且性能表现也比较好,所以当初就选择它作为内置负载算法。关于新增其他负载均衡算法,其他算法像最少连接、一致性 Hash 等,可能需要引入新的参数和额外的逻辑(可能会带来性能损耗),我还在调研,慢慢会加入新的负载算法的。

from gnet.

luyu6056 avatar luyu6056 commented on May 22, 2024

我建议以fd来分配loop,取得连接fd分配之后,将fd分配到 idx为nfd%svr.subLoopGroup.len()的loop里。
那么我们来复现疑问场景。
loop总数为2,fd为1分配到loop1,fd为2分配到loop0。fd2断开,重新再连,获得的fd还是2,2%2=0,这时候分配到loop0,实现均衡:smile:

from gnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.