Created
April 23, 2019 06:31
-
-
Save ayende/02d82aa43e88c3c441be1699c8bc71e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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