Last active
December 14, 2015 10:29
-
-
Save kijanawoodard/5072572 to your computer and use it in GitHub Desktop.
Write a lot of documents to raven db
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
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
using System.Net; | |
using System.Threading.Tasks; | |
using Raven.Client; | |
using Raven.Client.Document; | |
using Xunit; | |
namespace Testing | |
{ | |
public class TestWriteSpeed | |
{ | |
[Fact] | |
public void WriteSpeed_RawSessionPerRequest() | |
{ | |
ServicePointManager.DefaultConnectionLimit = int.MaxValue; | |
const int docs = 100 * 1000; | |
var watch = Stopwatch.StartNew(); | |
using (var store = new DocumentStore { Url = "http://remote_machine:8080", DefaultDatabase = "WriteSpeed" }.Initialize()) | |
{ | |
var tasks = Enumerable.Range(0, docs) | |
.Select(x => StoreDocument(store, x)) | |
.ToArray(); | |
Task.WaitAll(tasks); | |
} | |
watch.Stop(); | |
Console.WriteLine("Elapsed: " + TimeSpan.FromMilliseconds(watch.ElapsedMilliseconds)); | |
Console.WriteLine("Processed: " + docs); | |
Console.WriteLine("rate: " + (docs) / (watch.ElapsedMilliseconds / 1000) + "/s"); | |
} | |
private Task StoreDocument(IDocumentStore store, int id) | |
{ | |
return Task.Factory.StartNew(() => | |
{ | |
var session = store.OpenSession(); | |
session.Store(new TestDocument { Id = "docs/" + id }); | |
session.SaveChanges(); | |
}, TaskCreationOptions.LongRunning); | |
} | |
class TestDocument | |
{ | |
public string Id { get; set; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment