Esempio n. 1
0
        public void Initialize()
        {
            _db = new SqlLocalDB();

            EventStore = new SqlEventStore(_db.ConnectionString);
            EventStore.Database.InitializeAsync().GetAwaiter().GetResult();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            for (; ;)
            {
                var ln = Console.ReadLine();
                if (ln == null)
                {
                    break;
                }
                var split = ln.Split(new[] { '\t', ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                try
                {
                    switch (split[0])
                    {
                    case "create":
                        SqlLocalDB.Create(database: split[1]);
                        break;

                    case "exit":
                        return;

                    default:
                        Console.Error.WriteLine($"unknown command: {split[0]}");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine($"[{ex.GetType()}]: {ex.Message}");
                }
            }
        }
Esempio n. 3
0
        private static async Task <double> AppendBenchmarkAsync(Func <string, ISqlEventStore> factory, int batchSize, Stopwatch sw, TimeSpan timeout)
        {
            using (var db = new SqlLocalDB())
            {
                var es = factory(db.ConnectionString);

                await es.Database.InitializeAsync();

                var list = new List <UncommittedEvent>();

                int n = 0;
                foreach (var e in GetUncommittedSource(1000, 100000))
                {
                    list.Add(e);

                    if (!(list.Count < batchSize))
                    {
                        var batch = list.ToArray();
                        n += batch.Length;
                        list.Clear();
                        await es.AppendAsync(batch);

                        if (!(sw.Elapsed < timeout))
                        {
                            return(n / sw.Elapsed.TotalSeconds);
                        }
                    }
                }

                return(n / sw.Elapsed.TotalSeconds);
            }
        }
Esempio n. 4
0
        private static async Task FillAsync()
        {
            using (var db = new SqlLocalDB())
            {
                var es = new SqlEventStore(db.ConnectionString);

                await es.Database.InitializeAsync();

                var marks = new List <double>();

                for (int i = 0; i < 100; i++)
                {
                    var sw = Stopwatch.StartNew();

                    await es.WithBulkCopyAppend().AppendAsync(GetUncommittedSource(1000, 100000));

                    var mark = 100000 / sw.Elapsed.TotalSeconds;
                    var size = new FileInfo(db.FileName).Length / (1024d * 1024d);

                    marks.Add(mark);

                    if (marks.Count > 1)
                    {
                        var fit = Fit.Line(Enumerable.Range(1, marks.Count).Select(x => (double)x).ToArray(), marks.ToArray());

                        Console.WriteLine($"{mark,9:N1} op/s {size,10:N0} MiB {fit.Item2,9:N1} op/s");
                    }
                    else
                    {
                        Console.WriteLine($"{mark,9:N1} op/s {size,10:N0} MiB");
                    }
                }
            }
        }
Esempio n. 5
0
        public void Cleanup()
        {
            foreach (var e in EventStore.GetEnumerable())
            {
                Debug.WriteLine($"{e.Id},{e.StreamId},{e.SequenceNumber},{e.TypeId},{e.Payload},{e.UncompressedSize},{e.Created}");
            }

            EventStore = null;

            _db.Dispose();
            _db = null;
        }
Esempio n. 6
0
        private static async Task AppendBenchmark2Async(Func <ISqlEventStore, ISqlEventStore> configuration, int batchSize, TimeSpan timeout)
        {
            using (var db = new SqlLocalDB())
            {
                var es = new SqlEventStore(db.ConnectionString);

                await es.Database.InitializeAsync();

                var list = new List <UncommittedEvent>();

                var sw = new Stopwatch();

                var es2 = configuration(es);

                int n = 0;
                foreach (var e in GetUncommittedSource(1000, 100000))
                {
                    list.Add(e);

                    if (!(list.Count < batchSize))
                    {
                        var batch = list.ToArray();
                        n += batch.Length;
                        list.Clear();

                        sw.Start();

                        await es2.AppendAsync(batch);

                        sw.Stop();

                        if (!(sw.Elapsed < timeout))
                        {
                            break;
                        }
                    }
                }

                Console.WriteLine($"{n / sw.Elapsed.TotalSeconds:N1} op/s");
            }
        }
Esempio n. 7
0
        private static async Task GetEnumerableStreamBenchmarkAsync(TimeSpan timeout)
        {
            using (var db = new SqlLocalDB())
            {
                var es = new SqlEventStore(db.ConnectionString);

                await es.Database.InitializeAsync();

                await es.WithBulkCopyAppend().AppendAsync(GetUncommittedSource(1000, 100000));

                var streamIdSet = es.GetEnumerable().Select(x => x.StreamId).Distinct().ToList();

                //

                var fs = new[] {
                    "default",
                    "unknown",
                };

                var xs = new[] {
                    new List <double>(),
                    new List <double>(),
                };

                for (int k = 0; k < 10; k++)
                {
                    var i = 0;
                    foreach (var f in new Func <ISqlEventStore, ISqlEventStore>[] {
                        x => x,
                    })
                    {
                        var y = f(es);

                        var sw = new Stopwatch();

                        var rnd = Randomness.Create();

                        int n = 0;
                        while (sw.Elapsed < timeout)
                        {
                            var streamId = streamIdSet[rnd.Next(streamIdSet.Count)];

                            var minSeq = 1;
                            var maxSeq = minSeq + rnd.Next(100);

                            sw.Start();

                            n += y.GetEnumerableStream(streamId, minSeq, maxSeq).Count();

                            sw.Stop();
                        }

                        var p = n / sw.Elapsed.TotalSeconds;
                        xs[i].Add(p);
                        i++;
                    }

                    Console.Write($"{k}");

                    for (int j = 0; j < 2; j++)
                    {
                        var p = xs[j][k];

                        var fit = Tuple.Create(0d, 0d);

                        if (xs[j].Count > 1)
                        {
                            fit = Fit.Line(Enumerable.Range(1, xs[j].Count).Select(x => (double)x).ToArray(), xs[j].ToArray());
                        }

                        Console.Write($" | {fs[j]}: {p,9:N1} op/s {fit.Item1,9:N1}+x*{fit.Item2,9:N1}");
                    }
                    Console.WriteLine();
                }
            }
        }