Multi-Threading and Transactions in OrientDB #9436
-
Hello, OrientDB community! I won't bore you with formalities, so I will jump right in: I have the following use-case: I need to import a metric ton of XML-modeled data into the OrientDB Graph Database. This data is consisting of the following:
Also, I use Ferma as an OGM and doing all my graph inquires via the Gremlin API of the OrientDB. So, my answer seemed to me to be pretty straight forward: multi-threading. But it wasn't as such... My problem: I tried a first draft of implementing a single threaded export of the simple data and a multi-threaded export of the complex data. My question: PS: Thank you so much for reading through my post and I hope this discussion may reach other developers that are troubled by a similar problem. Cheers, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi Alex, Welcome to OrientDB Community! Multi-threading is not a complex topic as long as you stick to a couple of basic rules. The first one is: never ever share connections and records between threads, always open, use and close a session in the same thread; if you need to share records between threads, pass RIDs and reload the record from inside the other thread. This is enough to be safe with the API contracts. The second rule is to consider the strengths and the limits of OrientDB transaction model. Optimistic transactions trade locking (ie. server overhead, less parallelism) with failures (ie. the need to retry transactions in case of collisions). The best way to have a good multi-threading with OrientDB is to keep the transaction scopes isolated, eg. if you have updates on two different schema classes, you can have one thread per class and you will never have collisions. Another thing: TinkerPop adds overhead and complexity to the whole thing, I'd strongly suggest to use the multi-model API directly (it has the exact same concepts and it's not so different) https://orientdb.com/docs/3.0.x/java/Java-MultiModel-API.html Thanks Luigi |
Beta Was this translation helpful? Give feedback.
Hi Alex,
Welcome to OrientDB Community!
Multi-threading is not a complex topic as long as you stick to a couple of basic rules.
The first one is: never ever share connections and records between threads, always open, use and close a session in the same thread; if you need to share records between threads, pass RIDs and reload the record from inside the other thread.
This is enough to be safe with the API contracts.
The second rule is to consider the strengths and the limits of OrientDB transaction model. Optimistic transactions trade locking (ie. server overhead, less parallelism) with failures (ie. the need to retry transactions in case of collisions).
In OrientDB, each record has a vers…