needlestack.balancers package

Submodules

needlestack.balancers.greedy module

class needlestack.balancers.greedy.GreedyAlgorithm[source]

Bases: needlestack.balancers.knapsack.Algorithm

Greedy algorithm that places the largest item in the lightest knapsack, then repeat until all items are placed somewhere.

add(items, knapsacks)[source]

needlestack.balancers.knapsack module

class needlestack.balancers.knapsack.Algorithm[source]

Bases: object

Superclass for algorithm to place items in knapsacks

add(items, knapsacks)[source]
rebalance(knapsacks)[source]
class needlestack.balancers.knapsack.Item(collection, shard)[source]

Bases: object

Item that goes into a knapsack

id

ID for item

collection
shard
quantity

How many of these item should exist

weight

How much this item weighs

property id
property quantity
property weight
class needlestack.balancers.knapsack.Knapsack(node, capacity=None)[source]

Bases: object

Knapsack that can hold multiple items

id

ID for knapsack

node

Value this knapsack is representing

items

Set of items in knapsack

current_weight

Current weight in the knapsack

capacity

Max weight for knapsack

add_item(item)[source]
capacity = None
property id
needlestack.balancers.knapsack.calculate_add(nodes, current_collections, add_collections, algorithm)[source]

Determine how to add a set of collections to an existing set of collections.

Return type

List[Collection]

needlestack.balancers.knapsack.calculate_rebalance(nodes, current_collections, algorithm)[source]
Return type

List[Collection]

Module contents