RavenDB 4 - Memory usage during streaming grows indefinitely

96 views
Skip to first unread message

Andrej Krivulčík

unread,
Apr 18, 2018, 3:52:50 AM4/18/18
to RavenDB - 2nd generation document database
When streaming, memory usage seems to grow without bounds:

In real-world scenario when trying to process ~9M documents, the usage grows to more than 10 GB (after around 200k documents) and eventually crashes.

Reproduction code (4.0.3-nightly-20180418-0400, both client and server):

using Raven.Client.Documents;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RavenDB4Tests.Tryouts
{
   
public static class StreamingMemory
   
{
       
public static async Task StreamingMemoryTest()
       
{
           
var rng = new Random();
           
using (var store = new DocumentStore
           
{
               
Urls = new[] { "http://localhost:8081" },
               
Database = "StreamingMemoryTest"
           
}.Initialize())
           
{
               
if (await ShouldInitData(store))
               
{
                    await
InitializeData(store);
               
}

               
using (var session = store.OpenAsyncSession())
               
{
                   
Console.WriteLine("Creating stream.");
                   
var query = session.Query<Doc>(collectionName: "Docs");
                   
var stream = await session.Advanced.StreamAsync(query);
                   
while (await stream.MoveNextAsync())
                   
{
                       
var doc = stream.Current.Document;
                       
if (doc.Id.EndsWith("000"))
                       
{
                           
Console.WriteLine($"Processing {doc.Id}");
                       
}
                        session
.Advanced.Evict(doc);
                   
}
                   
Console.WriteLine("Finished processing.");
               
}
           
}
       
}

       
private static async Task<bool> ShouldInitData(IDocumentStore store)
       
{
           
using (var session = store.OpenAsyncSession())
           
{
               
var doc = await session.LoadAsync<Doc>("doc/1");
               
return doc == null;
           
}
       
}

       
private static async Task InitializeData(IDocumentStore store)
       
{
           
var start = 0;
           
var batches = 50;
           
Console.WriteLine("Generating data.");
           
var rng = new Random();
           
for (int batchNo = start; batchNo < start + batches; batchNo++)
           
{
               
Console.WriteLine($"{DateTime.Now.ToLongTimeString()}: Generating batch {batchNo + 1}/{batches}");
               
using (var session = store.OpenAsyncSession())
               
{
                   
for (int i = 1; i <= 10000; i++)
                   
{
                        await session
.StoreAsync(new Doc { Id = "doc/" + (batchNo * 10000 + i), IntVal = i, IntVals = Enumerable.Range(1, 50).ToDictionary(x => x.ToString(), _ => rng.Next()) });
                       
}
                    await session
.SaveChangesAsync();
               
}
           
}
           
Console.WriteLine("Data generated.");
       
}

       
public class Doc
       
{
           
public string Id { get; set; }
           
public int IntVal { get; set; }
           
public Dictionary<string, int> IntVals { get; set; }
       
}
   
}
}

Oren Eini (Ayende Rahien)

unread,
Apr 22, 2018, 9:23:17 AM4/22/18
to ravendb
Hi,
Reproduced locally, Tal is working on a fix

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tal Weiss

unread,
Apr 22, 2018, 11:32:34 AM4/22/18
to RavenDB - 2nd generation document database
Hi Andrej,
You can track the progress here http://issues.hibernatingrhinos.com/issue/RDBC-162 
It seems we were not disposing of the blittable object in the async version of streaming, also invoking evict won't help since those documents are not been tracked by the session so we can't dispose of them (from evict).
--

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Tal Weiss l Core Team Developer Mobile:+972-54-802-4849

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811l Skype: talweiss1982

RavenDB paving the way to "Data Made Simplehttp://ravendb.net/ 

Reply all
Reply to author
Forward
0 new messages