alfredox
alfredox

Reputation: 4352

Splitting data in batches based on performance (load balancing)

I am looking to write a small load balancing algorithm to determine how much data to send to each server based on it's performance metric (it's weight). My question is similar to this one: Writing a weighted load balancing algorithm

However that one is more for servers that get a constant stream of data. My case will be run once, and split between multiple systems (2 at the time). Load needs to be split so all data is processed and completed at same time.

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

I am doing this in python, what would be an equation to take in a list of numbers and split up the batch # based on the weight? Ex. Receive weights = [4.1, 7.3, 2.5] and img_count = 5000?

Upvotes: 0

Views: 246

Answers (1)

Salvador Dali
Salvador Dali

Reputation: 222461

You just need to calculate how much work a unit weight can perform and then multiply you weight by the unit work. Here are a couple of lines in 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]

At the end do something with rounding and you have what you want

Upvotes: 1

Related Questions