Discussion: Session + Concurrency
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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:
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.