Skip to content

Instantly share code, notes, and snippets.

@ayende
Created April 23, 2019 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayende/02d82aa43e88c3c441be1699c8bc71e9 to your computer and use it in GitHub Desktop.
Save ayende/02d82aa43e88c3c441be1699c8bc71e9 to your computer and use it in GitHub Desktop.
public class TestItem
{
public long A, B;
}
public static class Program
{
public static async Task Main(string[] args)
{
using (var store = new DocumentStore
{
Urls = new[] { "http://localhost:8080" },
Database = "test"
})
{
store.Initialize();
var sp = Stopwatch.StartNew();
var tasks = new Task[10];
for (int i = 0; i < 10; i++)
{
tasks[i] = WriteMillionDocs(store);
}
Task.WaitAll(tasks);
Console.WriteLine(sp.ElapsedMilliseconds);
}
}
private static async Task WriteMillionDocs(DocumentStore store)
{
using (var bulk = store.BulkInsert())
{
for (int i = 0; i < 1_000_000; i++)
{
var t = bulk.StoreAsync(new TestItem
{
A = i,
B = i
});
if (t.IsCompleted)
continue;
await t;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment