I would be interested in thoughts on my setup. I have been running neo4j on community edition with no speed issues but recently moved to a professional (lowest tier) AuraDB instance and things seem very slow and i am trying to work out why.
I am using fastapi and manage connections with a class which i call from a helper function as below. This has worked well up to now but since moving to Aura I am wondering if there is. a better way to manage the connection pool?
def run_query(query, params=""):
neo4j_conn = Neo4jConnect(General.BOLT_URL, General.BOLT_DEFAULT_USER, General.BOLT_DATABASE_PASSWORD)
try:
result = neo4j_conn.run_query_with_retries(query, params)
except exceptions.ServiceUnavailable as e:
result = f"Query failed after multiple retries: {e}"
neo4j_conn.close()
return result
c
lass Neo4jConnect:
def __init__(self, uri, user, password):
self.driver = GraphDatabase.driver(uri, auth=basic_auth(user, password),
connection_timeout=60.0, connection_acquisition_timeout=120.0)
def close(self):
self.driver.close()
def run_query_with_retries(self, query, parameters, max_retries=5, backoff_factor=0.5):
for attempt in range(max_retries):
try:
with self.driver.session() as session:
result = session.run(query, parameters=parameters)
return result.data()
except exceptions.ServiceUnavailable as e:
if attempt < max_retries - 1:
sleep_time = backoff_factor * (2 ** attempt)
print(f"Attempt {attempt + 1} failed, retrying in {sleep_time} seconds...")
time.sleep(sleep_time)
else:
print("Max retries reached, raising exception")
raise e