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 Qt中实现子线程和管理线程类之间实时通信
  • ¥15 cacls 命令如何解除锁定文件夹?
  • ¥50 C++使用TWAIN协议如何实现A3幅面扫描仪扫描A4横向
  • ¥15 如何在sql server里完成筛选
  • ¥15 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?