Ejemplo n.º 1
0
 /// <summary>
 /// If <paramref name="disablePacking"/> is set to true Packer only releases
 /// unused memory pages back to OS and does not perform compression.
 /// TODO This setting per stream
 /// </summary>
 /// <param name="streamLogManager"></param>
 /// <param name="stateStorage"></param>
 /// <param name="disablePacking"></param>
 public Packer(StreamLogManager streamLogManager, StreamLogStateStorage stateStorage, bool disablePacking = false)
 {
     _streamLogManager = streamLogManager;
     _stateStorage     = stateStorage;
     _disablePacking   = disablePacking;
     Pool = new SpreadsThreadPool(
         new ThreadPoolSettings(1 + Math.Max(Environment.ProcessorCount / 2 - 1, 0),
                                ThreadType.Background,
                                "Packer_pool",
                                ApartmentState.Unknown, ex =>
     {
         ThrowHelper.FailFast("Unhandled exception in Packer thread pool: \n" + ex);
     }, 0, ThreadPriority.BelowNormal));
 }
Ejemplo n.º 2
0
 public Completable(SpreadsThreadPool tp)
 {
     _tp = tp;
 }
Ejemplo n.º 3
0
        public void CouldReadWriteZeroLogViaThreadPool()
        {
            Console.WriteLine("Starting test");
            Console.Out.Flush();
#pragma warning disable 618
            Settings.DoAdditionalCorrectnessChecks = false;
#pragma warning restore 618
            var path          = TestUtils.GetPath(clear: true);
            var repoName      = "CouldWriteAndReadLog0";
            var processConfig = new ProcessConfig(path);

            StartupConfig.StreamLogBufferPoolFlags = LMDBEnvironmentFlags.NoSync;
            StartupConfig.StreamBlockIndexFlags    = LMDBEnvironmentFlags.NoSync;

            var slm = new StreamLogManager(processConfig, repoName, null, 20 * 1024, false, true);

            var count = TestUtils.GetBenchCount(200 * 1024 * 1024L, 1000);

            var tp = new SpreadsThreadPool(new ThreadPoolSettings(6, ThreadType.Foreground, "Log0Pool",
                                                                  ApartmentState.Unknown, null, 0, ThreadPriority.AboveNormal));

            var writer = new Thread(() =>
            {
                for (int i = 1; i <= count; i++)
                {
                    var x = i;

                    ThreadPool.UnsafeQueueUserWorkItem(o =>
                    {
                        (o as NotificationLog).Append((StreamLogNotification)(ulong)x);
                    }
                                                       , slm.Log0);
                }
            });

            writer.Priority = ThreadPriority.Highest;
            writer.Start();

            var reader = new Thread(() =>

            {
                try
                {
                    var c = 0L;
                    using (Benchmark.Run("ZL Read", count, true))
                    {
                        var zlr = new NotificationLog.Reader(slm.Log0, CancellationToken.None);
                        var sw  = new SpinWait();
                        while (zlr.MoveNext())
                        {
                            // if (zlr.MoveNext())
                            {
                                // Thread.SpinWait(1);
                                c++;
                                if (c % 10_000_000 == 0)
                                {
                                    Console.WriteLine($"{c:N0} |  MQL {zlr.MissedQueueLength}");
                                }

                                if (c >= count - 1000)
                                {
                                    if (zlr.MissedQueueLength > 0)
                                    {
                                        Console.WriteLine("Missed queue non empty");
                                        continue;
                                    }

                                    Console.WriteLine(
                                        $"Finished at CurrentVersion: " + zlr.CurrentVersion.ToString("N"));
                                    break;
                                }
                            }
                            //else
                            //{
                            //    sw.SpinOnce();
                            //    if (sw.NextSpinWillYield)
                            //    {
                            //        sw.Reset();
                            //        if (zlr.CurrentVersion > slm.Log0.State.GetZeroLogVersion())
                            //        {
                            //            Console.WriteLine("Reached the end");
                            //            // break;
                            //        }
                            //        // Console.WriteLine($"Spinning in ZLMN: " + zlr.CurrentVersion.ToString("N"));
                            //    }
                            //}
                        }

                        if (zlr.MaxStall > MaxStall)
                        {
                            MaxStall = zlr.MaxStall;
                        }

                        Console.WriteLine("STALLS: " + zlr.StallCount);
                        Console.WriteLine("-------------------------");
                        Console.WriteLine("MAX STALL: " + zlr.MaxStall.ToString("N"));
                        Console.WriteLine("GLOBAL MAX STALL: " + MaxStall.ToString("N"));
                        Console.WriteLine("-------------------------");
                        zlr.Dispose();
                    }

                    Console.WriteLine("Read count: " + c.ToString("N"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Reader exception: " + ex);
                }
            });

            reader.Priority = ThreadPriority.Highest;
            reader.Start();

            reader.Join();

            tp.Dispose();
            tp.WaitForThreadsExit();

            Benchmark.Dump();

            Thread.Sleep(100);

            Console.WriteLine("ROTATE CNT: " + (slm.Log0.RotateCount));
            Console.WriteLine("STALE VERSION CNT: " + (slm.Log0.StaleVersionCount));

            //slm.Dispose();
            //slm2.Dispose();
            GC.KeepAlive(slm); GC.KeepAlive(slm);
            slm.Dispose();

            Thread.Sleep(1000);
        }