pythonsolrsolrclient

How to close a SolrClient connection?


I am using SolrClient for python with Solr 6.6.2. It works as expected but I cannot find anything in the documentation for closing the connection after opening it.

def getdocbyid(docidlist):
    for id in docidlist:
        solr = SolrClient('http://localhost:8983/solr', auth=("solradmin", "Admin098"))
        doc = solr.get('Collection_Test',doc_id=id)
        print(doc)

I do not know if the client closes it automatically or not. If it doesn't, wouldn't it be a problem if several connections are left open? I just want to know if it there is any way to close the connection. Here is the link to the documentation: https://solrclient.readthedocs.io/en/latest/


Solution

  • The connections are not kept around indefinitely. The standard timeout for any persistent http connection in Jetty is five seconds as far as I remember, so you do not have to worry about the number of connections being kept alive exploding.

    The Jetty server will also just drop the connection if required, as it's not required to keep it around as a guarantee for the client. solrclient uses a requests session internally, so it should do pipelining for subsequent queries. If you run into issues with this you can keep a set of clients available as a pool in your application instead, then request an available client instead of creating a new one each time.

    I'm however pretty sure you won't run into any issues with the default settings.