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

Huge Memory & CPU Usage #48

Closed
KeKl opened this issue Aug 13, 2015 · 2 comments
Closed

Huge Memory & CPU Usage #48

KeKl opened this issue Aug 13, 2015 · 2 comments
Labels

Comments

@KeKl
Copy link

KeKl commented Aug 13, 2015

Hello,

I compared three versions of a test application. I saved a lot (10^7) objects of a type with three properties of type double.
The first version was coded with saving to a file with json serialization (Newtonsoft Json). The second was with litedb. The third with simply saving to a txt-File (File.WriteAllLines).

Code LiteDB:

// Open database (or create if not exits)
using(var db = new LiteDatabase(@".\LiteDB.db"))
{
    // Get customer collection
    var col = db.GetCollection<Node>("nodes");
    col.Insert(nodes);
}

The results are:

Version Memory Usage Disk Space Usage Time Needed [ms]
Newtonsoft Json ~500MB 673MB 68,630ms
LiteDB ~6 675MB 3 476MB 497,464ms
Text File ~500MB 950MB 38,913ms

Is there a faster way of saving bigger datas?

@mbdavid
Copy link
Owner

mbdavid commented Aug 13, 2015

Hi @KeKl, thanks for your comment.

Performance and memory use drops in LiteDB when you are working with huge mass of data. This reason is because LiteDB implement a full transaction and journal backup save. Transactions are memory only (thats why use too many memory) and journal write in disk twice.

To works fast with huge data in LiteDB, try to use:

using(var db = new LiteDatabase(@"filename=.\LiteDB.db; journal=false"))
{
    var col = db.GetCollection<Node>("nodes");
    col.InsertBulk(nodes);
}
  • nodes var must returns and IEnumerable<Node> and will be better if uses yield return

This code must run fast, but never as Newtonsoft or Text File. LiteDB implements indexes (at least _id index), data in pages, and has a much more complex data structure.

I have some plans to remove some features (like transactions and journals) in prior be simple, less memory usage and faster.

@KeKl
Copy link
Author

KeKl commented Aug 22, 2015

Hi @mbdavid,

thank you for your answer.

I tested also your implementation. It´s faster.

Thank you!

Regards,
Kevin

@KeKl KeKl closed this as completed Aug 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants