Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What level of performance should I expect from RavenDB?

Tags:

ravendb

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.

like image 855
Chris Avatar asked Jul 07 '10 19:07

Chris


1 Answers

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.

like image 137
Matt Warren Avatar answered Nov 19 '22 11:11

Matt Warren