任务队列问题 #1345
Unanswered
JieTrancender
asked this question in
Q&A
任务队列问题
#1345
Replies: 1 comment 2 replies
-
|
我觉得你要的是尽量不干扰外部消息。所以,在你处理自己的内部任务的间隙,判断一下 mqlen 的长度,然后如果有外部消息调用 skynet.yield 就够了。 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
问题起源:某些对全服玩家遍历然后执行的操作会导致服务被单个协程长时间占用并触发
maybe endless loop警告。根据前面云大的评论参照https://github.com/cloudwu/skynet/blob/master/lualib/snax/gateserver.lua#L65 改了一版
此时报警不会再出现,但是外部新请求依然会排队很久才能执行(因为去执行全服玩家遍历操作的任务协程排在前面)。
为了解决这个问题采用了折中的方法:新起一个任务队列服务,当前服务将遍历玩家需要执行的操作发送到任务队列服务中去然后自己再一个一个任务处理,此时外部请求和处理任务队列里面的任务优先级一致。
代码见:https://gist.github.com/JieTrancender/2b3deb76671a5a38f7124d98d6d50f2e
但是当前解决方法需要服务发送一次请求去队列服务并且新增接口供任务被消耗,请问有更好的方法实现这个需求吗?
Beta Was this translation helpful? Give feedback.
All reactions