I want to import 100 million entries from a text file (each row is one csv-like entry) into a RavenDB database. What is the fastest way to do this?
Additional Notes:
I have not any indexes yet (I will create them after inserting the data). RavenDB is running in service mode on local machine with no security enhancements (yet; because I am still testing RavenDB). This test will run on 2 different machines, 1) 2 cores 4GB ram 2) 8 cores 12 GB ram.
I have done inserting a portion of this data (2 million entries) into RavenDB but it was not as fast as I would like. By using OpenAsyncSession and calling SaveChangesAsync for every 1024 records and again creating a new session by calling OpenAsyncSession and not waiting for return Task (returned by SaveChangesAsync) after 500`000 entries or so, I get an "Index out of range" exception that I can not root out. But if I wait for tasks to end (by creating them same as number of cores), process will succeed but not fast enough.
This code ran successfully:
using (var reader = new StreamReader(@"D:\*\DATA.TXT", Encoding.UTF8))
{
string line = null;
IAsyncDocumentSession session = null;
var tasks = new List<Task>();
var locCount = 0;
while ((line = reader.ReadLine()) != null)
{
if (string.IsNullOrWhiteSpace(line)) continue;
var loc = Parse(line);
if (session == null) session = documentStore.OpenAsyncSession();
session.Store(loc);
locCount++;
if (locCount % 1024 == 0 && session != null)
{
try
{
var t = session.SaveChangesAsync();
tasks.Add(t);
session = null;
}
catch (Exception x)
{
// ... something ...
}
}
if (tasks.Count >= NUMBER_OF_CORES)
{
Task.WaitAll(tasks.ToArray());
tasks.Clear();
}
}
if (session != null)
{
if (tasks.Count > 0)
{
Task.WaitAll(tasks.ToArray());
tasks.Clear();
}
session.SaveChangesAsync().Wait();
session = null;
}
}
Thanks