Giter Club home page Giter Club logo

Comments (4)

buptmiao avatar buptmiao commented on May 23, 2024

个人认为定时器和消息队列本来就没有一一对应关系,而是两类事件,一个是时间事件一个是消息事件。这个模式在redis中也有类似应用。关键代码在 Oneloop中的这一行:

bool bSucc = m_oMessageQueue.peek(psMessage, iTimeoutMs);

该timeout值是时间堆中的最小超时时间,这个时候程序阻塞timeout ms。如果来消息了,阻塞退出,执行消息。如果直到超时都没接到消息,那么同样阻塞退出,下一个loop执行该超时事件。这样设计的目的是使得两类事件都能够及时和准时执行。

from phxpaxos.

chenneal avatar chenneal commented on May 23, 2024

@buptmiao 感谢你的回复,你说的那个函数我是看过的,iTimeoutMs 只是作为锁等待最大时间的依据而已。你说的确实在理,这样的处理应该算是一种优化处理。但是这样 A 虽然是按照消息的顺序处理完毕,但是事实 B 我们是变向的增加了它的超时时间的(将 A 多余的时间过渡给了 B),某些情况会导致发现 B 的超时事件处理动作是往后延迟的,不过这对程序的正确性肯定是没有影响的。

你说的 A 和 B 都能够去处理,但是其实按照原本的超时设定 B 应该是直接去处理超时事件了才对。

from phxpaxos.

buptmiao avatar buptmiao commented on May 23, 2024

时间堆里面的时间都是绝对时间,导致事件处理滞后的原因可能来自前一个事件的处理函数执行时间过长。

from phxpaxos.

chenneal avatar chenneal commented on May 23, 2024

这几天又看了一下,开始的理解确实有误。phxpaxos 每次会再发送 message 到其它节点之前会设定一个定时器,待接收到其它节点发来的 message 时会扔到 消息队列 之中,之所以先取出最小的 timer 作为阻塞依据是为了不妨碍下一个超时事件的处理。

from phxpaxos.

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.