Handle timeouts while connecting to cassandra
I have been recently playing with Cassandra a lot using Python cassandra client.
One issue I saw a lot while timeouts connecting cassandra. The default timeout set in the client library is 5 seconds and it isn’t very intuitive how to increase it.
from cassandra.cluster import Cluster
from cassandra.cluster import ExecutionProfile
from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import EXEC_PROFILE_DEFAULT
auth_provider = PlainTextAuthProvider(username='username', password='password')
profile = ExecutionProfile(request_timeout=60)
cluster = Cluster(
['hostnanme'],
auth_provider=auth_provider,
execution_profiles={EXEC_PROFILE_DEFAULT: profile},
connect_timeout=120,
)
session = cluster.connect("database")
The above coode snippet increases the connect timeout and request timeout to 120 and seconds respectively.