Example #1
0
        static void TestWritingAndPerformance(EndlessFileStream.EndlessFileStream fileStream = null)
        {
            var list = fileStream ?? new EndlessFileStream.EndlessFileStream(new EndlessFileStreamSettings {
                BaseDirectory = @"C:\test\FileArray", MaxLogFileSizeInMByte = 1
            });
            long      size  = 0;
            Stopwatch w     = Stopwatch.StartNew();
            int       index = 0;

            int maxExecutionTimeMinutes = 15;

            Console.WriteLine($"Running now for {maxExecutionTimeMinutes}");
            for (; ;)
            {
                string entry = Guid.NewGuid().ToString() + ":" + (++index).ToString();
                list.Writer.WriteToFileStream(entry);
                size += entry.Length; // Roughly - string in utf8 might be different to byte in size
                if (w.ElapsedMilliseconds > 1000)
                {
                    Console.WriteLine($"{(double)size / (double)w.ElapsedMilliseconds * 1000.0 / 1024.0 / 1024.0} MB/s");
                    Task.Delay(100).Wait();
                    w    = Stopwatch.StartNew();
                    size = 0;
                }

                if (w.Elapsed.Minutes > maxExecutionTimeMinutes)
                {
                    break;
                }
            }
        }
Example #2
0
        static void ReadWhileWrite()
        {
            var stream = new EndlessFileStream.EndlessFileStream(new EndlessFileStreamSettings {
                BaseDirectory = @"C:\test\FileArray", MaxLogFileSizeInMByte = 1
            });
            Task w = Task.Run(() => TestWritingAndPerformance(stream));

            Stopwatch watch = Stopwatch.StartNew();
            int       maxExecutionTimeMinutes = 15;

            Console.WriteLine($"Running now for {maxExecutionTimeMinutes}");

            for (; ;)
            {
                try
                {
                    var entries = stream.Reader.ReadEntries(FileStreamDirection.Forward, 10);
                    foreach (var a in entries)
                    {
                        Console.WriteLine($"READ: {a}");
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine($"Exception while reading endless stream: {e.Message}");
                }

                if (watch.Elapsed.Minutes > maxExecutionTimeMinutes)
                {
                    break;
                }
            }


            // ReSharper disable once FunctionNeverReturns
        }