Alarming Performance when using LiteDB for simple record saving
See original GitHub issueI had a requirement for a certain application where a large number of messages will be received and they need to be stored. so I chose LiteDB and used it with default configuration as mentioned in the documentation. Here is the class that I used:
public class HolderMessage
{
public long Id { get; set; }
public GridMessageType MessageType { get; set; }
public HolderMessageState State { get; set; }
public DateTime AddedOn { get; set; }
public byte[] Message { get; set; }
}
In some other class
public Database(FileInfo file)
{
_db = new LiteDB.LiteDatabase(file.FullName);
_inbox = _db.GetCollection<HolderMessage>("Inbox");
_outbox = _db.GetCollection<HolderMessage>("Outbox");
Action<LiteDB.LiteCollection<HolderMessage>> PrepareIndex = (arg) =>
{
arg.EnsureIndex(x => x.Id, new LiteDB.IndexOptions { EmptyStringToNull = true, Unique = true, TrimWhitespace = true });
arg.EnsureIndex(x => x.AddedOn, new LiteDB.IndexOptions { EmptyStringToNull = true, Unique = false, TrimWhitespace = true, IgnoreCase = true });
arg.EnsureIndex(x => x.MessageType, new LiteDB.IndexOptions { EmptyStringToNull = true, Unique = false, TrimWhitespace = true });
};
PrepareIndex(_inbox);
PrepareIndex(_outbox);
}
yet at some other location I’m saving the messages
public void Push(Message msg)
{
var mail = new HolderMessage
{
Id = ++_counter,
AddedOn = DateTime.Now,
MessageType = msg.Kind, // this is enum
Message = Common.Utility.Serialize(msg), // this returns a byte array
State = HolderMessageState.UnProcessed // this is an enum
};
_queue.Insert(mail);
}
and when we call Push() during testing, it gave the shockingly poor performance ever
var watch = new System.Diagnostics.Stopwatch();
watch.Start();
for(var i = 1; i<10000;i++)
storage.Inbox.Push(CreaterMessage(new List<string> { $"Message:{i}" }));
watch.Stop();
so what exactly is wrong? is the configuration a problem or something else? because as the code is, it gives 20 records per second speed. i.e 10,000/ watch.TotalSeconds
Issue Analytics
- State:
- Created 7 years ago
- Comments:21 (9 by maintainers)
Top Results From Across the Web
c# - Performance issue while converting to .ToList ...
I am using LiteDB to store approx.1 million records. When i retrieve records from LiteDb after filtering and convert .ToList() from IQueryable, ...
Read more >Ask HN: Have you used SQLite as a primary database?
I use SQLite in production for my SaaS[1]. It's really great — saves me money, required basically no setup/configuration/management, ...
Read more >Overview - LiteDB :: A .NET embedded NoSQL database
LiteDB is a simple, fast and lightweight embedded . ... LiteDB improves search performance by using indexes on document fields or expressions.
Read more >Amazon SimpleDB – Simple Database Service
Amazon SimpleDB is a simple database storage solution that allows developers to simply store & query data items via web services requests, saving...
Read more >The database I wish I had
When I use an application on the web, it should save data into my database ... Having a local database would solve all...
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
but why would a database not perform adequately at regular operations and insist on bulk operations? That is something I do not understand. I cannot use Sql Server because the app I’m working on is a small one that will run as a part of bigger app. All I wanted to use LiteDB for, was persistent cache which now I feel was a wrong choice.
My conclusion is
@MercedeX You’re saying you need a database able to perform 10000 operations per second. If a disk based DBMS seems to have more than that, it uses caching, either internally or via the OS. Since you insist that this violates your consistency model (else bulk insertion would be possible), all changes must be flushed to disk immediately. Before that, obviously, the database has to read at least its header for each operation. Never mind that it probably has to read a few more pages.
So all of the 10000 operations require at least 1 disk read and write naturally, on a regular HDD instead of an SSD. Regular hard disks physically do not support this. For instance, a 15k rpm SAS drive has only around 200 IOPS. So if you find any offline DBMS that can actually do what you want, let me know.