# Distributed counters via scripting

**URL:** <https://discuss.elastic.co/t/distributed-counters-via-scripting/10464>\
**Category:** Elasticsearch\
**Created:** [January 23, 2013, 12:37am UTC](https://discuss.elastic.co/t/distributed-counters-via-scripting/10464 "2013-01-23T00:37:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drew\_Broadley](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@Drew\_Broadley](https://discuss.elastic.co/u/Drew_Broadley)\
**Post date:** [January 23, 2013, 12:37am UTC](https://discuss.elastic.co/t/distributed-counters-via-scripting/10464/1 "2013-01-23T00:37:30Z")

</div>

Hi there,

I'm trying to find out information about how this works at a lower level.

Things like Cassandra have taken a great deal of effort to create  
distributed counters, and I don't see any mention of how concurrent writes  
are handled etc.

I would like to know how this performs under load, under a node being down,  
and under concurrent write scenarios:

ctx.\_source['counter'] += 1;

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [February 1, 2013, 3:24pm UTC](https://discuss.elastic.co/t/distributed-counters-via-scripting/10464/2 "2013-02-01T15:24:30Z")

</div>

If you are referring to incrementing counter using Update API[http://www.elasticsearch.org/guide/reference/api/update.html](http://www.elasticsearch.org/guide/reference/api/update.html) it  
really depends on the amount of load. The operation is done on the primary  
shard without any locks, so under heavy load, I supposed, you might  
experience a significant number of retries. When node with primary shard  
goes down, the primary status is immediately reassigned to one of replicas,  
so the operation will just move to another node.

On Tuesday, January 22, 2013 7:37:30 PM UTC-5, Drew Broadley wrote:

> Hi there,
> 
> I'm trying to find out information about how this works at a lower level.
> 
> Things like Cassandra have taken a great deal of effort to create  
> distributed counters, and I don't see any mention of how concurrent writes  
> are handled etc.
> 
> I would like to know how this performs under load, under a node being  
> down, and under concurrent write scenarios:
> 
> ctx.\_source['counter'] += 1;

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:53am UTC](https://discuss.elastic.co/t/distributed-counters-via-scripting/10464/3 "2017-07-06T02:53:32Z")

</div>

Closed on July 6, 2017, 2:53am UTC


