Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Args = args;

            Console.WriteLine(BenchmarkApplication.ApplicationName);
            Console.WriteLine(BenchmarkApplication.Paths.Plaintext);
            Console.WriteLine(BenchmarkApplication.Paths.Json);
            Console.WriteLine(BenchmarkApplication.Paths.Fortunes);
            Console.WriteLine(BenchmarkApplication.Paths.SingleQuery);
            Console.WriteLine(BenchmarkApplication.Paths.Updates);
            DateHeader.SyncDateTimer();
            BatchUpdateString.Initalize();

            BuildWebHost(args).Run();
        }
Ejemplo n.º 2
0
        public async Task <World[]> LoadMultipleUpdatesRows(int count)
        {
            using (var db = _dbProviderFactory.CreateConnection())
            {
                db.ConnectionString = _connectionString;
                await db.OpenAsync();

                using (var updateCmd = db.CreateCommand())
                    using (var queryCmd = CreateReadCommand(db))
                    {
                        var results = new World[count];
                        for (int i = 0; i < count; i++)
                        {
                            results[i] = await ReadSingleRow(db, queryCmd);

                            queryCmd.Parameters["@Id"].Value = _random.Next(1, 10001);
                        }

                        updateCmd.CommandText = BatchUpdateString.Query(count);

                        for (int i = 0; i < count; i++)
                        {
                            var id = updateCmd.CreateParameter();
                            id.ParameterName = $"@Id_{i}";
                            id.DbType        = DbType.Int32;
                            updateCmd.Parameters.Add(id);

                            var random = updateCmd.CreateParameter();
                            random.ParameterName = $"@Random_{i}";
                            random.DbType        = DbType.Int32;
                            updateCmd.Parameters.Add(random);

                            var randomNumber = _random.Next(1, 10001);
                            id.Value                = results[i].Id;
                            random.Value            = randomNumber;
                            results[i].RandomNumber = randomNumber;
                        }

                        await updateCmd.ExecuteNonQueryAsync();

                        return(results);
                    }
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            Args = args;

            Console.WriteLine(BenchmarkApplication.ApplicationName);
            Console.WriteLine(BenchmarkApplication.Paths.Plaintext);
            Console.WriteLine(BenchmarkApplication.Paths.Json);
            Console.WriteLine(BenchmarkApplication.Paths.Fortunes);
            Console.WriteLine(BenchmarkApplication.Paths.SingleQuery);
            Console.WriteLine(BenchmarkApplication.Paths.Updates);
            Console.WriteLine(BenchmarkApplication.Paths.MultipleQueries);
            DateHeader.SyncDateTimer();

            var host   = BuildWebHost(args);
            var config = (IConfiguration)host.Services.GetService(typeof(IConfiguration));

            BatchUpdateString.Initialize(config.Get <AppSettings>().Database);
            host.Run();
        }
Ejemplo n.º 4
0
        private static DbCommand CreatCommand(int count)
        {
            DbCommand cmd = new Npgsql.NpgsqlCommand();

            cmd.CommandText = BatchUpdateString.Query(count);
            for (int i = 0; i < count; i++)
            {
                var id = cmd.CreateParameter();
                id.ParameterName = IDParamereNames[i];
                id.DbType        = DbType.Int32;
                cmd.Parameters.Add(id);

                var random = cmd.CreateParameter();
                random.ParameterName = RandomParamereNames[i];
                random.DbType        = DbType.Int32;
                cmd.Parameters.Add(random);
            }
            return(cmd);
        }
Ejemplo n.º 5
0
        public async Task <World[]> LoadMultipleUpdatesRows(int count)
        {
            var results = new World[count];

            using (var db = new NpgsqlConnection(_connectionString))
            {
                await db.OpenAsync();

                var(queryCmd, queryParameter) = CreateReadCommand(db);
                using (queryCmd)
                {
                    for (int i = 0; i < results.Length; i++)
                    {
                        results[i] = await ReadSingleRow(queryCmd);

                        queryParameter.TypedValue = _random.Next(1, 10001);
                    }
                }

                using (var updateCmd = new NpgsqlCommand(BatchUpdateString.Query(count), db))
                {
                    var ids     = BatchUpdateString.Ids;
                    var randoms = BatchUpdateString.Randoms;

                    for (int i = 0; i < results.Length; i++)
                    {
                        var randomNumber = _random.Next(1, 10001);

                        updateCmd.Parameters.Add(new NpgsqlParameter <int>(parameterName: ids[i], value: results[i].Id));
                        updateCmd.Parameters.Add(new NpgsqlParameter <int>(parameterName: randoms[i], value: randomNumber));

                        results[i].RandomNumber = randomNumber;
                    }

                    await updateCmd.ExecuteNonQueryAsync();
                }
            }

            return(results);
        }