tags:

views:

117

answers:

1

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.

+1  A: 

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:

  • Batch up writes (which you are doing). I'm not sure you need to close and then re-open the session though, you should just be able to call SaveChanges()
  • Set the transaction mode to lazy (Raven/TransactionMode)
  • Do the imports asynchronously, i.e from several threads

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.

Matt Warren
I did try all of these and the performance gain wasn't noticable. I guess RavenDB is just too slow for my usage scenarios (write heavy). I'll give you the answer anyway, but the issue is kind of unresolvable at this point.
Chris
You might want to post this on the RavenDB mailing list http://groups.google.com/group/ravendb/. I'm far from a RavenDB expert so you might get a better answer.
Matt Warren