Exemple #1
0
        public Producer(int id, StrategyKind strategy, int timesPerSec = 50, int windowSize = 1024, int totalSize = 1024 * 1024)
        {
            Strategy    = strategy;
            TotalSize   = totalSize;
            WindowSize  = windowSize;
            TimesPerSec = timesPerSec;
            Shared      = Marshal.AllocCoTaskMem(TotalSize);

            _period = TimeSpan.FromSeconds(1) / TimesPerSec;

            _quit = new ManualResetEventSlim(false);

            _worker = new Thread(Worker);
            _worker.Start(id);
        }
        private async Task StartTest(TimeSpan duration, int producerId, StrategyKind producerStrategy, StrategyKind consumerStrategy)
        {
            Console.Write($"Producer: {producerStrategy,-10} - Consumer: {consumerStrategy,-10} ");

            var producerFactory = new ProducerFactory();

            using (var producer = producerFactory.Create(producerId, producerStrategy))
            {
                var consumerFactory = new ConsumerFactory();
                var consumer        = consumerFactory.Create(consumerStrategy);

                consumer.Consume(producer);

                await Task.Delay(duration);

                Console.WriteLine($"Min:{consumer.Min.TotalMilliseconds,6:0.00}ms - Max:{consumer.Max.TotalMilliseconds,6:0.00}ms");
            }
        }
 public Producer CreateProducer(int id, StrategyKind strategy, int timesPerSec = 50, int windowSize = 1024, int totalSize = 1024 * 1024)
 {
     return(new Producer(id, strategy, timesPerSec, windowSize, totalSize));
 }
Exemple #4
0
 public Consumer(StrategyKind strategy)
 {
     Strategy = strategy;
 }