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

看了源码round timer 这块代码没看明白呢 #231

Closed
lik0914 opened this issue Aug 29, 2018 · 5 comments
Closed

看了源码round timer 这块代码没看明白呢 #231

lik0914 opened this issue Aug 29, 2018 · 5 comments

Comments

@lik0914
Copy link

lik0914 commented Aug 29, 2018

如题,谁能给指教一下呢

@liyonglion
Copy link

@lik0914
round timer代码如下:
func (r *Round) Timer(rn int) *time.Timer {
return &(r.timers[rn%r.options.Timer])
}
rn在调用的地方递增,添加time的所有操作都会均匀的分散到各个time.Timer对象上,这样不会对单个对象操作太大的压力,time.Timer使用切片实现了一个类似最小堆的算法,在堆得开头是最先超时的time点,没调用一次TImer.Add操作,都有可能调整一次堆。

@liyonglion
Copy link

@Terry-Mao 有一个疑问,在go time.TImer源码里面已经实现了最小堆算法,只需要复用Timer即可。为什么该代码里面还需要实现一次类似最小堆算法呢?golang timer资料

@Terry-Mao
Copy link
Owner

因为有全局大锁争用,在密集连接发送时候,容易出现futex 争用,所以通过自己实现timer,然后减少对系统层面的timer调用

@xiaoxiaoyu85
Copy link

@Terry-Mao 首先感谢开源大作,已经拜读了,收益不少。有几个问题: 从tcpWriteProto开始的数据发送,没有设置发送超时,这样comet发送goroutine会被挂起,直到底层epoll接收到新的"通知事件",这里方便优化下加个超时吗?

@weisd
Copy link

weisd commented Aug 15, 2019

超时后什么处理?消息丢弃?

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

6 participants