dtcaw02086 2015-06-01 22:28
浏览 19
已采纳

转到:并发和优先级排序

I have n ~=1000 jobs running on outside servers, each tied to a go-routine in my program. I started the jobs at different times, and they finish roughly in the order they were started, but that's not guaranteed.

From each go-routine I poll its corresponding server job: is it done yet? My outbound requests are rate-limited, so I need to poll smartly.

I want to prioritize polling by go-routines whose jobs were started earlier. The way I'm doing it now, I have a channel that represents my rate limit, and all go-routines wait to acquire a value from this channel, poll their server, and then put a value back.

But, there's no guarantee that these go-routines would even read randomly (much less in priority order), because the behavior of multiple go-routines reading on the same channel is undefined.

Could someone guide me as to how to think about this problem? It doesn't have to be specific, but I'm not sure what primitives and data structures I would use in Go to read from channels in priority order, while taking into account rate-limiting.

It seems difficult because individual goroutines do not know the state of the whole program -- which of their colleague routines were started first, etc. They should merely be fed whether or not they should poll their server at any given time.

Thank you.

  • 写回答

1条回答 默认 最新

  • duancaoqin6683 2015-06-01 22:48
    关注

    You have heard of Weighted Fair Queues? That is a well developed way to schedule such that a prediction is made about which job should theoretically complete first, and that is the one that is serviced.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置