# Python elasticsearch performance

**URL:** <https://discuss.elastic.co/t/python-elasticsearch-performance/163587>\
**Category:** Elasticsearch\
**Created:** [January 9, 2019, 4:56pm UTC](https://discuss.elastic.co/t/python-elasticsearch-performance/163587 "2019-01-09T16:56:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![revelc33](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revelc33/32/123408_2.png) [@revelc33](https://discuss.elastic.co/u/revelc33)\
**Post date:** [January 9, 2019, 4:56pm UTC](https://discuss.elastic.co/t/python-elasticsearch-performance/163587/1 "2019-01-09T16:56:00Z")

</div>

i am trying to make 300 queries per second to my Elasticsearch from my script, but i am not very sure how can i make in an optimal way reusing the connections.

`  
from elasticsearch import Elasticsearch  
import \_thread

es = Elasticsearch( [{ 'host' : "127.0.0.1" 'port': 9200 , 'max\_clients' : 100000 }] )

def myThreadFunc(es):  
result = es.msearch( body = myquery, max\_concurrent\_searches = 100 ,request\_timeout = 0.6)  
makeSomethingwithResult(result)  
return 0

whille True:  
for i in range(10):  
\_thread.start\_new\_thread(myThreadFunc,(es),)  
time.sleep(1)  
`  
is the "es" object going to deal with reusing connections and keep alives( if it is necessary)?

When i check **GET /\_nodes/stats** on my ES the **'http' -\> "total\_opened"** the number increase very quickly. If the connections are keeped alive it's supposed this value has to increase only when connections are expired and opened again?

---

<div class="post-metadata">

**Author:** ![revelc33](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revelc33/32/123408_2.png) [@revelc33](https://discuss.elastic.co/u/revelc33)\
**Post date:** [January 9, 2019, 5:00pm UTC](https://discuss.elastic.co/t/python-elasticsearch-performance/163587/2 "2019-01-09T17:00:44Z")

</div>

@honzakral @Honza_Kral

---

<div class="post-metadata">

**Author:** ![honzakral](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/honzakral/32/44958_2.png) [@honzakral](https://discuss.elastic.co/u/honzakral)\
**Post date:** [January 9, 2019, 5:13pm UTC](https://discuss.elastic.co/t/python-elasticsearch-performance/163587/3 "2019-01-09T17:13:11Z")

</div>

Hi! Yes, the `es` object is thread safe and will indeed reuse the connection. There can still be an increase in the connections (not to mention that every time you check it it will increase as well) but that should stabilize over time.

---

<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:** [February 6, 2019, 5:28pm UTC](https://discuss.elastic.co/t/python-elasticsearch-performance/163587/4 "2019-02-06T17:28:36Z")

</div>

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