Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好,请教一个问题,这个框架写逻辑用map都要加锁吗 #35

Open
jame9988 opened this issue Mar 25, 2025 · 3 comments
Open

Comments

@jame9988
Copy link

jame9988 commented Mar 25, 2025

// Start 启动节点

func (n *Node) Start() {
n.setState(cluster.Work)

n.startTransporter()

n.registerServiceInstance()

n.proxy.watch(n.ctx)

go n.dispatch()  //处理请求和事件

n.debugPrint()

n.runHookFunc(cluster.Start)

}

//麻将例子代码

Image

Image
不是只有dispatch这个协程处理消息吗

@dobyte
Copy link
Owner

dobyte commented Mar 25, 2025

node节点本身处理消息是单线程的,故而你在在没有多线程操作map的情况下是不需要加锁的。

@jame9988
Copy link
Author

node节点本身处理消息是单线程的,故而你在在没有多线程操作map的情况下是不需要加锁的。

感谢大佬的解答,逻辑单线程处理,实际项目中会成为性能瓶颈吗?逻辑中如果不是纯内存操作的话

@dobyte
Copy link
Owner

dobyte commented Mar 26, 2025

node节点本身处理消息是单线程的,故而你在在没有多线程操作map的情况下是不需要加锁的。

感谢大佬的解答,逻辑单线程处理,实际项目中会成为性能瓶颈吗?逻辑中如果不是纯内存操作的话

理论上来讲单线程在绝大多数业务场景中都会是一个性能瓶颈点。故而开发者需要根据自身业务特点来选择合适的模型。在实际的业务开发过程中,一般都是结合各个模型的优缺点进行混用,并不存在一招吃遍天下的绝技。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants