cancel
Showing results for 
Search instead for 
Did you mean: 

Question about python neo4j-driver processing muti-threads (concurrent)

mading0817
Node Clone

I was wondering how is the concurrent performance of neo4j.
My python test code as followed:

from neo4j import GraphDatabase
import datetime
import threading

neo4j_db = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password"))


def get_count_r(tx):

    query = """
            MATCH ()-[r]-()
            RETURN COUNT(r)
            """

    return tx.run(query)


def thread_as_user():
    start_time = datetime.datetime.now()
    with neo4j_db.session() as session:
        the_result_data = session.read_transaction(get_count_r)
    end_time = datetime.datetime.now()
    print(end_time - start_time, the_result_data)


for i in range(100):
    t = threading.Thread(target=thread_as_user)
    t.start()

The code is basically to simulate a hundred users to access neo4j database.
The result as followed:


It is pretty wired that the number of the results which with the same time will be increased by 1. why is that?
What is the correct or best way to assess neo4j if I use multi-threads in python?
My goal is to guarantee the neo4j database could process 100 concurrent requests in production environment within 1000ms, Did I miss any principles or usages? Please let me know or tell me where to find the answers.

Thanks,
Regards

0 REPLIES 0