Created
December 1, 2011 16:44
-
-
Save ToJans/1418094 to your computer and use it in GitHub Desktop.
Performance test using Scritchy file storage
This file contains hidden or 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
01/12/2011 17:40 321.352.624 GLOBAL.msgs | |
01/12/2011 17:40 77.779.616 HEADER_TaskId_Tasks.1.msgs | |
01/12/2011 17:40 86.990.360 HEADER_TaskId_Tasks.2.msgs | |
01/12/2011 17:40 81.873.280 HEADER_TaskId_Tasks.3.msgs | |
01/12/2011 17:40 74.709.368 HEADER_TaskId_Tasks.4.msgs | |
5 bestand(en) 642.705.248 bytes |
This file contains hidden or 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.IO; | |
using System.Linq; | |
using System.Text; | |
using Scritchy.Domain; | |
using Scritchy.Infrastructure.Implementations.EventStorage; | |
using Scritchy.Infrastructure.Implementations.EventStorage.Adapters; | |
namespace RawStorageExample | |
{ | |
class Program | |
{ | |
[ProtoBuf.ProtoContract(ImplicitFields=ProtoBuf.ImplicitFields.AllPublic)] | |
public class Message | |
{ | |
public string TaskId { get; set; } | |
public string Content {get;set;} | |
} | |
public class Task : AR {} | |
// shortcut for testing; only supports Message as a type | |
class MessageProtoSerializer : ISerializer | |
{ | |
public object Deserialize(Scritchy.Infrastructure.Implementations.EventStorage.Models.EventBlob blob) | |
{ | |
byte[] byteArray = Encoding.ASCII.GetBytes(blob.SerializedData); | |
using (var stream = new MemoryStream(byteArray)) | |
{ | |
return ProtoBuf.Serializer.Deserialize<Message>(stream); | |
} | |
} | |
public void Serialize(object instance, ref Scritchy.Infrastructure.Implementations.EventStorage.Models.EventBlob blob) | |
{ | |
using (var ms = new MemoryStream()) | |
{ | |
ProtoBuf.Serializer.Serialize<Message>(ms, (Message)instance); | |
blob.SerializedData = Encoding.ASCII.GetString(ms.ToArray()); | |
blob.SerializationProtocol = "ProtoBuf"; | |
} | |
} | |
} | |
static void Main(string[] args) | |
{ | |
var adapter = new StreamAdapter((x, a) => FileStorageStreamGetter.GetStreamForFileName(x + ".msgs", a)); | |
var store = new EventStore(adapter, new MessageProtoSerializer()); | |
var startTime = DateTime.Now; | |
var endTime = startTime; | |
var msgcount = 0; | |
double msec; | |
Console.WriteLine("Generate events first? (Y/N)"); | |
if (Console.ReadKey().Key == ConsoleKey.Y) | |
{ | |
foreach (var f in Directory.EnumerateFiles(".", "*.msgs")) | |
{ | |
File.Delete(f); | |
} | |
while (true) | |
{ | |
var msgs = new Message[]{ | |
new Message { TaskId = "Tasks.1", Content = "Muahahah"}, | |
new Message { TaskId = "Tasks.2", Content = "1 million dollars"}, | |
new Message { TaskId = "Tasks.3", Content = "Said Dr Evil"}, | |
new Message { TaskId = "Tasks.4", Content = "O RLY"} | |
}; | |
store.SaveEvents(msgs); | |
msgcount += msgs.Length; | |
endTime = DateTime.Now; | |
if ((endTime - startTime).TotalSeconds > 60) | |
break; | |
} | |
msec = (endTime - startTime).Duration().TotalMilliseconds; | |
var mbytes = (double)(Directory.EnumerateFiles(".", "*.msgs") | |
.Select(x => new FileInfo(x).Length).Sum()) / 1024 / 1024; | |
Console.WriteLine("Time to store {0} messages ({2} MB) : {1} msecs, msgs/sec = {3}, MB/sec = {4}", msgcount, msec, mbytes, (double)msgcount * 1000 / msec, mbytes * 1000 / msec); | |
} | |
Console.WriteLine(); | |
Console.WriteLine("Reading back messages"); | |
// read back all | |
startTime = DateTime.Now; | |
endTime = startTime; | |
var readbackmsgcount = 0; | |
foreach (var v in store.GetNewEvents()) | |
{ | |
readbackmsgcount++; | |
} | |
endTime = DateTime.Now; | |
Debug.Assert(msgcount!=0 && readbackmsgcount == msgcount, "The count of the events read does not match the count of the events written"); | |
msec = (endTime - startTime).Duration().TotalMilliseconds; | |
Console.WriteLine("Time to read {0} messages : {1} msecs, msgs/sec = {2}", readbackmsgcount, msec, (double)readbackmsgcount * 1000 / msec); | |
Console.ReadLine(); | |
} | |
} | |
} |
This file contains hidden or 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
Generate events first? (Y/N) | |
y | |
Time to store 4093664 messages (612,931488037109 MB) : 60000,4318 msecs, | |
msgs/sec = 68227,2423246127, MB/sec = 10,2154512834208 | |
Reading back messages | |
Time to read 4093664 messages : 81044,6355 msecs, msgs/sec = 50511,2272360087 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment