【发布时间】:2020-06-14 07:56:18
【问题描述】:
我目前正在尝试找到解决此文档Hash Code 2017 - Streaming Videos 中所述问题的有效解决方案。
TLDR; 为了最大限度地减少 youtube 视频的延迟,缓存服务具有有限的 容量被使用。然而,并不是每个缓存都连接到每个 端点,并不是每个端点都请求相同的视频。目标是 以最小化整个网络的整体延迟。
我的方法是简单地遍历每个端点和每个请求块,并找到每个视频大小延迟减少最多的最佳缓存(我将称之为 request密度)。
当最佳缓存已经达到其容量时,我尝试存储它以换取 请求密度较小的视频,或者如果没有其他可能,则使用不同的缓存(请注意数据中心也是我模型中的缓存)。
def distribute_video_requests(endpoint, excluding_caches=set()):
caches = endpoint.cache_connections - excluding_caches
for vr in endpoint.video_requests:
optimal_cache = find_optimum(caches, vr)
exchange = try_put(optimal_cache, vr)
if exchange["conflicting"]:
excluding_caches.add(optimal_cache)
for elm in exchange["affected"]:
distribute_video_requests(elm["from"], excluding_caches)
for ep in endpoints:
distribute_video_requests(ep)
您可以将其可视化为Brazil nut effect,其中视频请求是按堆栈排序的不同密度的片段。
我解释所有这些的原因是因为我无法真正判断我的解决方案是否合适,如果不是:有什么更好的方法?
【问题讨论】:
标签: algorithm sorting optimization combinatorics