# How to correctly determine the weight of a node

**URL:** <https://discuss.elastic.co/t/how-to-correctly-determine-the-weight-of-a-node/224871>\
**Category:** Elasticsearch\
**Created:** [March 24, 2020, 3:31pm UTC](https://discuss.elastic.co/t/how-to-correctly-determine-the-weight-of-a-node/224871 "2020-03-24T15:31:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ld\_pvl](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@ld\_pvl](https://discuss.elastic.co/u/ld_pvl)\
**Post date:** [March 24, 2020, 3:31pm UTC](https://discuss.elastic.co/t/how-to-correctly-determine-the-weight-of-a-node/224871/1 "2020-03-24T15:31:31Z")

</div>

Hey Team,

I'm trying to calculate the weights of each node based on the below two settings taken from [shard balancing heuristics](https://www.elastic.co/guide/en/elasticsearch/reference/current/shards-allocation.html#_shard_balancing_heuristics):

```
cluster.routing.allocation.balance.shard
cluster.routing.allocation.balance.index

```

Let's say we have the below scenario:

```
Node 1 has 2 indexes: index A and index B
Node 1 also has 3 primary shards and 3 replica shards (6 shards in total).
cluster.routing.allocation.balance.shard = 0.45f
cluster.routing.allocation.balance.index = 0.55f

```

Then as per the documentation:

1. `cluster.routing.allocation.balance.shard` defines the weight factor for the total number of shards allocated on a node:

2. `cluster.routing.allocation.balance.index` defines the weight factor for the number of shards per index allocated on a specific node:

3. Weight of Node 1 is the sum of weights calculated from 1. and 2.:

Is the above a correct way of calculating a node's weight?

Cheers,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 21, 2020, 3:31pm UTC](https://discuss.elastic.co/t/how-to-correctly-determine-the-weight-of-a-node/224871/2 "2020-04-21T15:31:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![Paul\_Le\_Tilly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_le_tilly/32/97836_2.png) [@Paul\_Le\_Tilly](https://discuss.elastic.co/u/Paul_Le_Tilly)\
**Post date:** [March 2, 2023, 9:59am UTC](https://discuss.elastic.co/t/how-to-correctly-determine-the-weight-of-a-node/224871/3 "2023-03-02T09:59:41Z")

</div>

Hey there,

I was wondering the same thing, and went on a little trip into [the rabbit hole](https://github.com/elastic/elasticsearch/blob/8bcecec21788b8100ecf576cf83086c6d68bfc02/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java#L287).

There you have the code for the WeightFunction class that compute the weight of each nodes.

And as you can see the [weight function](https://github.com/elastic/elasticsearch/blob/8bcecec21788b8100ecf576cf83086c6d68bfc02/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java#L305) does the computation on 4 characteristics of a node:

- ShardsLoad = Number of shard on the node - Avg number of shards per node in the cluster
- IndexLoad = Number of shard for a given index - Avg number of shards for a given index in the cluster
- WriteLoad = [Write load on a node](https://github.com/elastic/elasticsearch/blob/8bcecec21788b8100ecf576cf83086c6d68bfc02/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java#L1311) - Avg write load
- DiskLoad = [Actual disk usage](https://github.com/elastic/elasticsearch/blob/8bcecec21788b8100ecf576cf83086c6d68bfc02/server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java#L1312) - Avg disk usage in the cluster

All of those are then multiplied by [their respective settings](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-cluster.html#shards-rebalancing-heuristics) and divided by the sum of all settings.

SumSettings = `cluster.routing.allocation.balance.shard` + `cluster.routing.allocation.balance.index` + `cluster.routing.allocation.balance.disk_usage` + `cluster.routing.allocation.balance.write_load`

So in the end you have:

Weight = ShardsLoad \* `cluster.routing.allocation.balance.shard` / SumSettings  
+ IndexLoad \* `cluster.routing.allocation.balance.index` / SumSettings  
+ WriteLoad \* `cluster.routing.allocation.balance.write_load` / SumSettings  
+ DiskLoad \* `cluster.routing.allocation.balance.disk_usage` / SumSettings
