Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I use Esent with the managed Esent wrapper?

Tags:

esent

I tried following the examples, using a Using statement to open an instance, create a session, attach to the database, open it, then perform some operations like opening a transaction and saving a record. But when I use this pattern for each operation. Each operation like a Save take around .5 second. So I think I am doing this wrong. but I am not sure how I should be doing this.

should I only have one Instance? can I have more if they are named differently?

can I / should I have more if I have more than one thread?

I see I can have multiple sessions open at the same time, I think that is OK but does every session need to be attached? should the database be opened for each session? I am getting inconsistent results when I test these various scenarios, Sometimes my tests pass sometimes I get exceptions , like trying to use a disposed object, or EsentTempPathInUseException.

So is there any guidance on how I should use this?

like image 868
Noel Avatar asked Jan 16 '23 13:01

Noel


1 Answers

I have found these answers elswhere or by trial and error but for anyone that sees them here...

You should have only one instance, creating the instance is very expensive it really is creating the database and because it self heals itself from a unexpected shut down it could be running those routines if needed. you cant open more than one instance if you name it something different it will create a second instance that is different from the first. If you overlap them then you will get an error.

No problem with multi-threading. Open a database once. Attach a session once. Sessions should not go across threads. You can have multiple threads with their own sessions each accessing the database.Make sure you dispose of managed escent objects. SO follow the examples to use "Using" statements or make sure that objects dispose of them.

EsentTempPathInUseException is thrown trying to open a second instance while a current instance is still in use.

The disposed object exceptions I was having was because I was overlapping the creating and disposition of Managed Esent objects when I should not be.

like image 170
Noel Avatar answered Feb 08 '23 13:02

Noel