I am trying to insert records into Cassandra using a multi threaded Python program. I am running this program simultaneously on 3 machines. For some time being records are getting inserted, but later I am getting below exception. I am using driver provided by datastax.
cassandra.cluster.NoHostAvailable
I did some search and found out (source: https://datastax.github.io/python-driver/api/cassandra/cluster.html)
exception cassandra.cluster.NoHostAvailable
Raised when an operation is attempted but all connections are busy, defunct, closed, or resulted in errors when used.
My question is:
1. Is this a normal exception one could face with too many connection to Cassandra.
2. How would I resolve this in a situation where I want to create many connection/session to/of cassandra. (I know creating too many session is not advisable, it impact server performance as each session consume a handful amount of memory)
Below is the code fragment.
cluster = Cluster(['192.168.1.21'])
session = cluster.connect('myNameSpace')
def insertInToCassandra(catRange):
for x in catRange:
//function to insert records into Cassandra table
ProductRange = [
range(900,920),
range(921,940),
range(941,960),
range(961,980),
range(981,1000)
]
# Make the Pool of workers
pool = ThreadPool(20)
# Open the urls in their own threads
# and return the results
results = pool.map(insertInToCassandra, ProductRange)
#close the pool and wait for the work to finish
pool.close()
pool.join()