panjf2000 / gnet

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
https://gnet.host
Apache License 2.0
9.71k stars 1.04k forks source link

What is the difference between reactor and eventloop? #401

Closed ccnlui closed 2 years ago

ccnlui commented 2 years ago

What is your question about gnet? My question came after reading the following in engine.go:

func (eng *engine) start(numEventLoop int) error {
    if eng.opts.ReusePort || eng.ln.network == "udp" {
        return eng.activateEventLoops(numEventLoop)
    }

    return eng.activateReactors(numEventLoop)
}

What are the functional difference between an event loop and a reactor? They seem very similar because both of them opens a number of *netpoll.Poller, creates new event loops, register them to the load balancer, etc...

I can tell the option ReusePort would create event loops instead of reactor, maybe a better question is when would you want to use the ReusePort option?

Thank you.

panjf2000 commented 2 years ago

They are two implementations, eventloop is the old one while reactor is the new one, eventloop consists of symmetric workers while reactor is composed of asymmetric workers: one main reactor and multiple sub reactors.