我希望编写一个小的负载平衡算法,以根据它的性能指标(它的权重)确定要发送到每个服务器的数据量。我的问题与此类似:Writing a weighted load balancing algorithm
然而,对于获得恒定数据流的服务器来说,更多的是更多。我的案例将运行一次,并在多个系统之间分配(当时为2个)。需要拆分负载,以便同时处理和完成所有数据。
Example 1:
We get a zip with 1,000 images
System #1: 3 s/img
System #2: 6 s/img
Since sys1 is 50% faster, it should receive double the data.
Sys1 receives: 667 images
Sys2 receives: 333 images
我在python中这样做,在数字列表中采用什么方程式并根据权重分割批次#?防爆。接收权重= [4.1, 7.3, 2.5]
和img_count = 5000
?
答案 0 :(得分:1)
您只需要计算单位重量可以执行的工作量,然后将您的体重乘以单位工作量。以下是python中的几行。
w = [4.1, 7.3, 2.5]
total = 5000
unit = total / sum(w)
res = [unit * i for i in w]
print res // [1474.820143884892, 2625.8992805755397, 899.2805755395684]
最后做一些圆整的事情,你有你想要的东西