optimize search logic for bridgeTweetSearchServant #190
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pr特性:
解决search繁忙时过度快速的生成大量goroutine。
这里使用go channel的mpmc特性,采用二级channel的机制,前一级channel由固定goroutine(“正式工”)消费channel的消息,channel如果满了,消息就会发送到二级channel,由二级channel的依存临时goroutine("临时工") 消费其中的消息,如果二级channel也满了,就新建goroutine来消费消息,并将该goroutine作为"临时工"监听二级channel中的消息,当“临时工”处理完手头的消息后,继续去抢二级channel中的消息,抢到了消息就消费(同时清零自己抢消息的计数),没抢到就等待一定时间再去抢,连续抢个固定来回后,直接返回退出(自我毁灭),如此就形成了一个有条件自生自灭的临时goroutine生成机制。