RavenDB client limited?

203 Views Asked by At

i'm very new to RavenDB and NOSQL in general. To test performance, i've written some very rough code with the RavenDB.Client. I'm simply starting 500 simultaneous tasks, each of which will simply create a test document, using a new session for every request with a random interval (1s-10s).

For some strange reason the requests are being sent in "bursts" going up to around 150 writes/s for a little under a minute. Traffic bursts?
And there's a few minutes between each of these bursts.

When debugging the application i can set a breakpoint at session.SaveChanges() and it will immediately get hit, so i'm unsure if this is a connection limit on the ravenDB.Client library (i suppose httpclient?) or if this is the actual database limiting the requests.

Any guesses or tips to why this could be, would be greatly appreciated!

Edit: Oddly when running only one task with no delay between requests, it does around 400-500 requests/s consistently.

private Database db = new Database();

    public MainWindow()
    {
        InitializeComponent();
    }       


    public async Task StartTests()
    {
        Random rnd = new Random();

        //Start write threads
        for(int i = 0; i < 500; i++)
        {
            Task.Run(() => WriteTest(rnd.Next(1000,10000)));
            await Task.Delay(200);
        }

        return;
    }


    private async Task<bool> WriteTest(int delay)
    {
        Raven ravenDB = new Raven(db.Store);

            int o = 0;
            while (o == 0)
            {
                //Write to DB
                ravenDB.CreateDocument();
                await Task.Delay(delay);
            }

        return true;
    }


    private void start_Click(object sender, RoutedEventArgs e)
    {
        StartTests();
    }


public class Database
{
    public IDocumentStore Store;

    public Database()
    {
        var store = new Lazy<IDocumentStore>(CreateStore);
        Store = store.Value;
    }      


    private static IDocumentStore CreateStore()
    {
        IDocumentStore store = new DocumentStore()
        {
            Urls = new[] { "http://localhost:3113" },
            Database = "IADB"
        }.Initialize();

        return store;
    }  
}


public class Raven
{
    IDocumentStore Store;

    public Raven(IDocumentStore store)
    {
        Store = store;
    }

    public void CreateDocument()
    {

        using (var session = Store.OpenSession())
        {

            session.Store(new TestObject
            {
                Name = "TestObjectName",
                RandomNumber = 123
            });

            session.SaveChanges();
        }

    }

    private class TestObject
    {
        public string Name { get; set; }
        public int RandomNumber { get; set; }
    }
}

}

1

There are 1 best solutions below

0
On

Not sure why i didn't think of it before, but i suddenly realized that the client had async methods and i tried those. When awaiting the document creation, i can keep the requests consistent. Here's the edited parts, if anyone should stumble into this issue, though i highly doubt it...

private async Task<bool> WriteTest(int delay)
{


    bool run = true;
    while (run)
    {
            //Write to DB
            await db.ravenDB.CreateDocument();
            await Task.Delay(delay);
    }

    return true;
}

public async Task CreateDocument()
{
    using (var session = Store.OpenAsyncSession())
    {

        await session.StoreAsync(new TestObject
        {
            Name = "TestObjectName",
            RandomNumber = 123
        });

        await session.SaveChangesAsync();
    }

}