Пример #1
0
        private void StartServer()
        {
            WebApp.Start<Startup>(url: tbServerBinding.Text);
            Log("Server started on " + tbServerBinding.Text);
            _lastCount = 0;
            _samples = 0;
            _secondsPassed = 0;
            int samplesPerSecond = (int)(1000 / chartInterval.Value);
            _lastRequests = new AvgQueue(samplesPerSecond*2);
            //var ca = chart.ChartAreas.First();
            //ca.AxisX.IntervalAutoMode = IntervalAutoMode.FixedCount;
            chart.Series["Series1"].LegendText = "Requests per interval";
            chart.Series["Series2"].LegendText = "Avg requests";
            //chart.Series["BarSeries"].YValuesPerPoint = samplesPerSecond;
            var timer = new Timer() {Interval = (int) chartInterval.Value};
            timer.Tick += (o, args) =>
            {
                _samples++;
                var count = Startup.Counter;
                labelCnt.Text = @"Total: " + count.ToString();
                var countPerPeriod = count - _lastCount;
                _lastRequests.Add(countPerPeriod);
                var avg = _lastRequests.Avg();
                if (_samples % samplesPerSecond == 0) //each second
                {
                    _secondsPassed++;
                    Log2("Avg per {0}ms: {1:0.00}", chartInterval.Value, avg);
                }
                chart.Series["Series2"].Points.Add(avg);
                chart.Series["Series1"].Points.Add(countPerPeriod);

                _lastCount = count;

            };
            timer.Start();
        }
Пример #2
0
        private void StartClient()
        {
            chart.Series["Series1"].LegendText = "Requests per interval";
            chart.Series["Series2"].LegendText = "Server count";
            _lastCount = 0;
            _samples = 0;
            _secondsPassed = 0;
            _lastServerCount = 0;
            int samplesPerSecond = (int)(1000 / chartInterval.Value);
            _lastRequests = new AvgQueue(samplesPerSecond*2);
            var requester = new Requester(tbUrl.Text, (int)tasksCount.Value, cbKeepAlive.Checked);
            requester.ExceptionHandler += exception =>
            {
                this.Invoke((MethodInvoker)delegate
                {
                    Log("Ex: {0},",exception.ToString());
                });
            };

            if (rbClientAsync.Checked)
            {
                requester.StartAsync(cts.Token);
            }
            else
            {
                requester.Start(cts.Token);
            }
            Log("Client started requesting " + tbUrl.Text);
            chart.Series["Series2"].IsXValueIndexed = false;
            chart.Series["Series1"].IsXValueIndexed = false;
            var timer = new Timer() { Interval = (int)chartInterval.Value };
            timer.Tick += (o, args) =>
            {
                _samples++;
                var count = requester.Count;
                var serverCount = requester.LastResult;
                if (_samples == 1)
                    _lastServerCount = serverCount;
                labelCnt.Text = @"Total: " + count.ToString();
                var countPerPeriod = count - _lastCount;
                _lastRequests.Add(countPerPeriod);
                if (_samples % samplesPerSecond == 0) //each second
                {
                    var avg = _lastRequests.Avg();
                    _secondsPassed++;
                    Log2("Avg per {0}ms: {1:0.00}", chartInterval.Value, avg);
                }
                if (_samples > 4 || serverCount - _lastServerCount < 3000)
                {
                    chart.Series["Series1"].Points.Add(countPerPeriod);
                    chart.Series["Series2"].Points.Add(serverCount - _lastServerCount);
                }

                _lastServerCount = serverCount;
                _lastCount = count;

            };
            timer.Start();
        }