public virtual async Task Process(CancellationToken outterToken)
        {
            _logging.Log(() => $"Starting {GetType().Name} test");
            Interlocked.Exchange(ref _idCounter, 0);

            if (ClientProcess == null)
            {
                throw new ArgumentException($"{nameof(ClientProcess)} is null");
            }

            DateTime start = DateTime.Now;

            try
            {
                using (var report = new MonitorReport(GetType().Name, _options, _logging))
                {
                    var tasks = new List <Task>();

                    foreach (var clientNumber in Enumerable.Range(0, _options.ClientCount))
                    {
                        tasks.Add(Task.Run(() => ClientProcess(report, clientNumber, outterToken)));
                    }

                    Task.WaitAll(tasks.ToArray());
                }
            }
            finally
            {
                int count = await GetCount();

                _testMetricManager.Add(new TestMetric(GetType().Name, count, DateTime.Now - start, _options.ClientCount, _options.BatchSize));
            }
        }
Пример #2
0
        public MonitorRate(MonitorReport report, string name)
        {
            Report = report;
            Name   = name;

            _timer             = new Timer(x => Flush(), null, _period, _period);
            _currentRateDetail = new RateDetail(name);
        }
Пример #3
0
        private async Task InternalClientProcess(MonitorReport report, int clientNumber, CancellationToken token)
        {
            string agentName = $"Client_{clientNumber}";

            using (var monitor = new MonitorRate(report, agentName))
            {
                while (!token.IsCancellationRequested)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add("Id", typeof(int));
                    dt.Columns.Add("Variable", typeof(int));
                    dt.Columns.Add("Description", typeof(string));

                    foreach (int index in Enumerable.Range(0, _options.BatchSize))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        int id  = Interlocked.Increment(ref _idCounter);
                        var row = new Row2(id);
                        dt.Rows.Add(row.Id, row.Variable, row.Description);
                    }

                    using (var conn = new SqlConnection(_configuration.SqlConnectionString))
                    {
                        conn.Open();

                        using (var bulkCopy = new SqlBulkCopy(_configuration.SqlConnectionString))
                        {
                            bulkCopy.DestinationTableName = "[App].[Import2]";
                            await bulkCopy.WriteToServerAsync(dt, token);
                        }
                    }

                    monitor.IncrementBatch();
                    monitor.IncrementNew(dt.Rows.Count);
                }
            }
        }
        private async Task InternalClientProcess(MonitorReport report, int clientNumber, CancellationToken token)
        {
            string agentName = $"Client_{clientNumber}";

            var itemList = new List <Row>();

            using (var monitor = new MonitorRate(report, agentName))
            {
                while (!token.IsCancellationRequested)
                {
                    foreach (int index in Enumerable.Range(0, _options.BatchSize))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        int id = Interlocked.Increment(ref _idCounter);
                        itemList.Add(new Row(id));
                    }

                    using (var conn = new SqlConnection(_configuration.SqlConnectionString))
                    {
                        conn.Open();

                        using (var bulkCopy = new SqlBulkCopy(_configuration.SqlConnectionString))
                        {
                            bulkCopy.DestinationTableName = "[App].[Import]";
                            var dataReader = new DataReader(itemList);
                            await bulkCopy.WriteToServerAsync(dataReader, token);
                        }
                    }

                    monitor.IncrementBatch();
                    monitor.IncrementNew(itemList.Count);

                    itemList.Clear();
                }
            }
        }
Пример #5
0
        private async Task InternalClientProcess(MonitorReport report, int clientNumber, CancellationToken token)
        {
            string agentName = $"Client_{clientNumber}";
            var    table     = new SqlTableParameter <Row>("items", "[dbo].[ImportList]");

            table.ColumnDefinitions.Add(new SqlColumnDefintion <Row>(nameof(Row.Id), SqlDbType.Int, x => x.Id));
            table.ColumnDefinitions.Add(new SqlColumnDefintion <Row>(nameof(Row.Variable), SqlDbType.Variant, x => x.Variable));
            table.ColumnDefinitions.Add(new SqlColumnDefintion <Row>(nameof(Row.Description), SqlDbType.NVarChar, x => x.Description, 50));

            using (var monitor = new MonitorRate(report, agentName))
            {
                while (!token.IsCancellationRequested)
                {
                    foreach (int index in Enumerable.Range(0, _options.BatchSize))
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }

                        int id = Interlocked.Increment(ref _idCounter);
                        table.Items.Add(new Row(id));
                    }

                    await new SqlExec(_configuration)
                    .SetCommand("[App].[InsertIntoImport]", CommandType.StoredProcedure)
                    .AddParameter(table)
                    .ExecuteNonQuery();

                    monitor.IncrementBatch();
                    monitor.IncrementNew(table.Items.Count);

                    table.Items.Clear();
                }
            }
        }