question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion: Session + Concurrency

See original GitHub issue

The javadoc for Session explicitly states that:

“Multiple sessions should be used when working with concurrency; session implementations are not thread safe.” “At most one transaction may exist in a session at any point in time. To maintain multiple concurrent transactions, use multiple concurrent sessions.”

Thus, in a context of a web application, it seems the best would be to have a pool of opened Sessions which map one to one with a thread pool (ExecutionContext) of the same size.

Also, it seems to me that this is something the library should provide out of the box. But it is still not clear to me how this should work. I am only sure the underlying EC should be supplied by the user.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
BalmungSancommented, Jul 21, 2020

After thinking a while about this and after carefully reading this I believe the best idea would be what Gabriel suggested in the first place, having some kind of semaphore that ensure each Session instance can only be used from a thread a the time. This will guarantee thread safety. geoffjohn11 proposal of hiding the Session also ensured thread safety, however creating and destroying sessions every time a query was made was costly and removed an important property of the system of being casually consistent.

If some downstream user wants to execute queries in parallel, then it would be his/her responsibility to instantiate many Sessions and load balance all the petitions between them.


I would try to implement this in the weekend. So if anyone has a different opinion and want to discuss it, please let me know during the week.

1reaction
geoffjohn11commented, Jan 16, 2020

@BalmungSan I created an example of sharing a neotypes Session across threads (which is easiest to do using the Scala Future effect type). Since there already was an example project using Akka http and futures in the examples repo, I used that instead of the http4s and IO file you gave me, just so I could get something going as quickly as possible.
My test repo is located here: https://github.com/geoffjohn11/sessionShare

Uncomment the duplicated line in “dangerMethod” to execute the “incrementMovieYear” method in different threads (executing in separate Scala Futures). This results in a neo4j session exception:

org.neo4j.driver.internal.NetworkSession.lambda$ensureNoOpenTx$35(NetworkSession.java:526)

'You cannot begin a transaction on a session with an open transaction; either run from within the transaction or use a different session.'

It looks to me that because reads and writes both open a transaction with beginTransactionAsync, and at most one transaction may exist in a session at any point in time (in the neo4j session doc), the action fails. The second thread can’t use the shared session because they both open a transaction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Session-based concurrency, declaratively | SpringerLink
Session -based concurrency is a type-based approach to the analysis of message-passing programs. These programs may be specified in an ...
Read more >
Concurrent Sessions - Stanford Teaching Commons
In this workshop, we'll discuss typical challenges around teaching with classroom discussions. We'll face those challenges by exploring facilitation frameworks ...
Read more >
Concurrent Sessions and Deep Dives - Annual Meeting
A Concurrent Session is a 60-minute session that could be in the form of presentation, case study, discussion, panel or step-by-step presentation.
Read more >
Concurrent Sessions Information | UT Symposium | UTHSC
Concurrent Session 1 | 10:30-11:10 ... Each faculty member will discuss essentials as well as innovative online methods of instruction.
Read more >
Sequential vs Concurrent Session Execution in a Workflow
Greetings - There is on-going discussion within our ETL team regarding the concurrent execution of sessions within a workflow. My stance is that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found