I've been looking for a good NoSQL database for some of our projects for quite some time and I recently discovered RavenDB which looks pretty awesome from a .NET support perspective, so I decided to try it out and write a little benchmark. First order of business was testing insert speed, using the following code:
class Program
{
private const int TEST_COUNT = 10000;
static void Main(string[] args)
{
var store = new DocumentStore();
store.Url = "http://localhost:8117";
store.Initialize();
var timer = Stopwatch.StartNew();
var session = store.OpenSession();
for (var i = 0; i < TEST_COUNT; i++)
{
session.Store(new TestEntity()
{
Name = "Test Entity"
});
if (i % 127 == 0)
{
session.SaveChanges();
session.Dispose();
session = store.OpenSession();
}
}
session.SaveChanges();
session.Dispose();
timer.Stop();
Console.WriteLine("Processed {0:n0} records", TEST_COUNT);
Console.WriteLine("Time elapsed: {0:n0} ms", timer.ElapsedMilliseconds);
Console.WriteLine("Records / sec: {0:n0}", TEST_COUNT / (timer.ElapsedMilliseconds / 1000d));
}
}
class TestEntity
{
public string Name { get; set; }
public DateTime Created { get; set; }
public TestEntity()
{
Created = DateTime.UtcNow;
}
}
The output is as follows:
Processed 10,000 records
Time elapsed: 9,531 ms
Records / sec: 1,049
Press any key to continue . . .
This is on a relatively fast machine (3ghz, 2gb ram running Windows 7)
Call me crazy, but 1000 inserts / sec is horribly slow, especially for documents that contain a mere two fields. Is this to be expected? I know RavenDB is optimized for reads, not writes, but this is pretty bad.
I don't know if you're going to get much faster than that due to the whole "optimised for reads, not write" thing.
But if you read through this thread there are some suggestions:
SaveChanges()
Raven/TransactionMode
)One other thing you could try is the embedded mode
, i.e change your session to
var documentStore = new DocumentStore { DataDirectory = "path/to/database/directory" };
documentStore.Initialize();
This bypasses the HTTP traffic and inserts documents directly, see the docs for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With