Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where do we initialize the connection? Is it in a global variable? If not, should we create a new connection each time we need to run a query? And, are these connections auto managed by a pool? #107

Open
tausifcreates opened this issue Aug 10, 2023 · 9 comments

Comments

@tausifcreates
Copy link

No description provided.

@jifalops
Copy link
Contributor

I'm using Axum and keep a neo4rs::Graph in the AppState. The connection is handled under the hood, but from what I recall reading the Go driver, each request starts a new session. The sessions use a connection pool.

@tausifcreates
Copy link
Author

I'm using Axum and keep a neo4rs::Graph in the AppState. The connection is handled under the hood, but from what I recall reading the Go driver, each request starts a new session. The sessions use a connection pool.

Hey! Thanks for sharing the insight. I am using a global varibale, OnceLock to be precise.

@knutwalker
Copy link
Collaborator

Graph should be you entrypoint and you should keep that one in a singleton-ish place, like the axum state as @jifalops mentioned. A static OnceLock is also ok, depending on your application.

Under the hood, a connection pool is used (and its size can be configured with max_connections). Every invocation of run, execute, or start_txn will get a new connection from the pool (possibly waiting until one is available).

We don't have sessions in the Rust driver yet.

@tausifcreates
Copy link
Author

tausifcreates commented Sep 29, 2023

Graph should be you entrypoint and you should...

@knutwalker Thanks for the insight :)

@tausifcreates
Copy link
Author

@knutwalker What is a session, to be exact, in the context of Neo4j driver?

@knutwalker
Copy link
Collaborator

@tausifcreates

The definition of a session is "A causally linked sequence of transactions.".

What that means is, that you've got an abstraction that allows you to run multiple transactions after one another in a way that enforces causal consistency on the database cluster, that is, make sure your queries are consistent to the rules that a Neo4j cluster provides (for example, you typically want to read your own writes). You need to work and handle so called bookmarks to do that and a session is an abstraction where this handling is done for you, by the driver. A session might be pinned to a single connection, so all queries run over the same connection (In neo4rs, every query or transaction acquires a new connection from the pool, which might be the same as before, or it might be a new one).

We don't support bookmark support in neo4rs yet, so we don't have to have sessions as well, but it's somewhere on the roadmap. For now it means, when you use neo4rs and have a cluster on the other side, we cannot enforce causal consistency and you might not read your own writes.

@tausifcreates
Copy link
Author

@knutwalker Thank you so much for taking the time to explain very clearly!

@tausifcreates
Copy link
Author

tausifcreates commented Jan 3, 2024

Also many thanks for the awesome work on neo4rs. For this crate, I could move my backend to Rust ecosystem:)

@knutwalker
Copy link
Collaborator

Thanks for the feedback, that's great to hear :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants