# Distributing primary shards?

**URL:** <https://discuss.elastic.co/t/distributing-primary-shards/67804>\
**Category:** Elasticsearch\
**Created:** [December 1, 2016, 8:29pm UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804 "2016-12-01T20:29:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxwell\_Flanders](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Maxwell\_Flanders](https://discuss.elastic.co/u/Maxwell_Flanders)\
**Post date:** [December 1, 2016, 8:29pm UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/1 "2016-12-01T20:29:52Z")

</div>

Hey there! I have one particularly high throughput logging cluster which processes about 1tb of data per day. Most of that data goes into a single index with 25 shards (which exactly matches the number of nodes in the cluster, intentionally).

I was looking at the cluster today and I noticed that the primary shards aren't actually distributed evenly across nodes in the cluster - some nodes have 2 primary shards, and some nodes have 0. Wouldn't the best configuration for maximum indexing speed be to have one primary shard per node?? There are almost no other relevant indices on that cluster.

Is there a setting I can set to tell elasticsearch not to allow two primary shards from the same index to live on the same node??

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [December 2, 2016, 8:52am UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/2 "2016-12-02T08:52:50Z")

</div>

Primaries and replicas do approximately the same amount of work when indexing so there is no need to balance the primaries.

---

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [December 2, 2016, 9:09am UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/3 "2016-12-02T09:09:28Z")

</div>

Nodes with primaries handle the indexing request and they follow-up with other nodes to ensure the replication completes. So, in a way they take more n/w resource and communication burden. No?

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [December 2, 2016, 9:21am UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/4 "2016-12-02T09:21:21Z")

</div>

> Nodes with primaries handle the indexing request and they follow-up with other nodes to ensure the replication completes. So, in a way they take more n/w resource and communication burden. No?

Technically yes, but practically no 😉 The communication burden is often negligible. There are only very rare cases where primary balance would bring a little bit more performance. Establishing and keeping primary balance comes at a cost as well though, as more shard shuffling needs to be done by the balancer when a node fails.

---

<div class="post-metadata">

**Author:** ![mosiddi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mosiddi/32/577_2.png) [@mosiddi](https://discuss.elastic.co/u/mosiddi)\
**Post date:** [December 2, 2016, 10:45am UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/5 "2016-12-02T10:45:49Z")

</div>

Yup. You are right.

---

<div class="post-metadata">

**Author:** ![Maxwell\_Flanders](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@Maxwell\_Flanders](https://discuss.elastic.co/u/Maxwell_Flanders)\
**Post date:** [December 2, 2016, 4:00pm UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/6 "2016-12-02T16:00:04Z")

</div>

Wait so as long as the TOTAL of primaries and replicas for an index is distributed evenly across all my nodes, I can consider my cluster to be essentially balanced is what you are saying??

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [December 2, 2016, 4:20pm UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/7 "2016-12-02T16:20:48Z")

</div>

Elasticsearch takes two properties into account for balancing shards:

- Having approximately the same number of shards on each node (independently of the index they belong to).
- Spreading the shards of the same index across the nodes (this is the one you mentioned).

As these goals can sometimes conflict, ES provides a setting to influence the importance of one goal over the other, see here:

[https://www.elastic.co/guide/en/elasticsearch/reference/current/shards-allocation.html#\_shard\_balancing\_heuristics](https://www.elastic.co/guide/en/elasticsearch/reference/current/shards-allocation.html#_shard_balancing_heuristics)

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [December 2, 2016, 4:22pm UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/8 "2016-12-02T16:22:34Z")

</div>

Also note that neither of the balancing properties I've just mentioned distinguish between primary or replica shards, they're treated as equal w.r.t. balancing.

---

<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:** [December 30, 2016, 4:22pm UTC](https://discuss.elastic.co/t/distributing-primary-shards/67804/9 "2016-12-30T16:22:52Z")

</div>

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