I am using the Python Elasticsearch API http://www.elasticsearch.org/guide/en/elasticsearch/client/python-api/current/
to interact with ES in my Python Flask application (server is Python
Tornado). Currently, as soon as the app gets a new user request, it does
esclient = Elasticsearch("127.0.0.1") and then uses this esclient to search
for the required data. But I recently read that ES has persistent
connections. So,
Should I save the esclient somewhere and reuse it instead of doing
esclient = Elasticsearch("127.0.0.1") for every request?
Would there be some resource leak if I forget about esclient after
the request and open a new one every time? Is there a way to close this
open connection?
I am also doing the same for another db, Redis in my app. Sorry, might seem
like a basic question but I am a bit confused.
For both elasticsearch and redis python clients you should just have one
instance and keep reusing it.
If you create new ones there will be some connections left hanging (though
gc should pick them up) but also both your app and elasticsearch itself
will be paying tthe overhead of creating and maintaining additional
connections, which is not good.
I am using the Python Elasticsearch API http://www.elasticsearch.org/guide/en/elasticsearch/client/python-api/current/
to interact with ES in my Python Flask application (server is Python
Tornado). Currently, as soon as the app gets a new user request, it does
esclient = Elasticsearch("127.0.0.1") and then uses this esclient to search
for the required data. But I recently read that ES has persistent
connections. So,
Should I save the esclient somewhere and reuse it instead of doing
esclient = Elasticsearch("127.0.0.1") for every request?
Would there be some resource leak if I forget about esclient after
the request and open a new one every time? Is there a way to close this
open connection?
I am also doing the same for another db, Redis in my app. Sorry, might
seem like a basic question but I am a bit confused.
For both elasticsearch and redis python clients you should just have one
instance and keep reusing it.
If you create new ones there will be some connections left hanging (though
gc should pick them up) but also both your app and elasticsearch itself
will be paying tthe overhead of creating and maintaining additional
connections, which is not good.
I am using the Python Elasticsearch API http://www.elasticsearch.org/guide/en/elasticsearch/client/python-api/current/
to interact with ES in my Python Flask application (server is Python
Tornado). Currently, as soon as the app gets a new user request, it does
esclient = Elasticsearch("127.0.0.1") and then uses this esclient to search
for the required data. But I recently read that ES has persistent
connections. So,
Should I save the esclient somewhere and reuse it instead of doing
esclient = Elasticsearch("127.0.0.1") for every request?
Would there be some resource leak if I forget about esclient after
the request and open a new one every time? Is there a way to close this
open connection?
I am also doing the same for another db, Redis in my app. Sorry, might
seem like a basic question but I am a bit confused.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.