Пример #1
0
        public static async Task MigrateAsync()
        {
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDb"].ConnectionString);

            sqlConnection.Open();
            var sqlDriver = new SqlDriver(MsSqlProvider.Instance, sqlConnection);

            var mongoDriver = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User");

            mongoDriver.Database.DropCollectionAsync("User").Wait();

            for (int i = 0; i < 128; i++)
            {
                var uid0 = i * 0x1000000;
                var uid1 = uid0 + 0xFFFFFF;

                var uids = new List <int>();

                mongoDriver.Database.GetCollection <BsonDocument>("User");

                var sql = $"SELECT [Uid] FROM tblUser WHERE [Uid] BETWEEN ${uid0} AND ${uid1}";
                using (var command = new SqlCommand(sql, sqlConnection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (await reader.ReadAsync())
                        {
                            var uid = (int)reader.GetValue(0);
                            uids.Add(uid);
                        }
                    }
                }

                var timer = new Stopwatch();
                timer.Start();
                Console.Write($"[Step ({i + 1}/128)] Count:{uids.Count} ");
                foreach (var uid in uids)
                {
                    var user = await sqlDriver.LoadUserAsync(uid);

                    await mongoDriver.CreateUserAsync(uid, user);
                }
                timer.Stop();

                var elapsed = timer.Elapsed.TotalSeconds;
                if (uids.Count > 0 && elapsed > 0)
                {
                    var rowPerSec = uids.Count / timer.Elapsed.TotalSeconds;
                    Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
Пример #2
0
        public static async Task MigrateAsync()
        {
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDb"].ConnectionString);
            sqlConnection.Open();
            var sqlDriver = new SqlDriver(MsSqlProvider.Instance, sqlConnection);

            var mongoDriver = new MongoDbDriver(
                ConfigurationManager.ConnectionStrings["MongoDb"].ConnectionString, "User");

            mongoDriver.Database.DropCollectionAsync("User").Wait();

            for (int i = 0; i < 128; i++)
            {
                var uid0 = i * 0x1000000;
                var uid1 = uid0 + 0xFFFFFF;

                var uids = new List<int>();

                mongoDriver.Database.GetCollection<BsonDocument>("User");

                var sql = $"SELECT [Uid] FROM tblUser WHERE [Uid] BETWEEN ${uid0} AND ${uid1}";
                using (var command = new SqlCommand(sql, sqlConnection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (await reader.ReadAsync())
                        {
                            var uid = (int)reader.GetValue(0);
                            uids.Add(uid);
                        }
                    }
                }

                var timer = new Stopwatch();
                timer.Start();
                Console.Write($"[Step ({i + 1}/128)] Count:{uids.Count} ");
                foreach (var uid in uids)
                {
                    var user = await sqlDriver.LoadUserAsync(uid);
                    await mongoDriver.CreateUserAsync(uid, user);
                }
                timer.Stop();

                var elapsed = timer.Elapsed.TotalSeconds;
                if (uids.Count > 0 && elapsed > 0)
                {
                    var rowPerSec = uids.Count / timer.Elapsed.TotalSeconds;
                    Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
Пример #3
0
        public static async Task ReadAsync(bool parallel)
        {
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDb"].ConnectionString);

            sqlConnection.Open();

            var sqlDriver = new SqlDriver(MsSqlProvider.Instance, sqlConnection);

            var uids = new List <int>();

            using (var command = new SqlCommand("SELECT [Uid] FROM tblUser", sqlConnection))
            {
                using (var reader = command.ExecuteReader())
                {
                    while (await reader.ReadAsync())
                    {
                        var uid = (int)reader.GetValue(0);
                        uids.Add(uid);
                    }
                }
            }

            Console.WriteLine(uids.Count);

            var repeatCount = 100;
            var timer       = new Stopwatch();

            timer.Start();

            for (int i = 0; i < repeatCount; i++)
            {
                var tasks = uids.Select(uid => sqlDriver.LoadUserAsync(uid));
                await tasks.WaitForComplete(parallel);
            }

            var elapsed   = timer.Elapsed.TotalSeconds;
            var rowPerSec = repeatCount * uids.Count / timer.Elapsed.TotalSeconds;

            Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
        }
Пример #4
0
        public static async Task ReadAsync(bool parallel)
        {
            var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlDb"].ConnectionString);
            sqlConnection.Open();

            var sqlDriver = new SqlDriver(MsSqlProvider.Instance, sqlConnection);

            var uids = new List<int>();
            using (var command = new SqlCommand("SELECT [Uid] FROM tblUser", sqlConnection))
            {
                using (var reader = command.ExecuteReader())
                {
                    while (await reader.ReadAsync())
                    {
                        var uid = (int)reader.GetValue(0);
                        uids.Add(uid);
                    }
                }
            }

            Console.WriteLine(uids.Count);

            var repeatCount = 100;
            var timer = new Stopwatch();
            timer.Start();

            for (int i = 0; i < repeatCount; i++)
            {
                var tasks = uids.Select(uid => sqlDriver.LoadUserAsync(uid));
                await tasks.WaitForComplete(parallel);
            }

            var elapsed = timer.Elapsed.TotalSeconds;
            var rowPerSec = repeatCount * uids.Count / timer.Elapsed.TotalSeconds;
            Console.WriteLine($"Elapsed: {(int)elapsed}s RowPerSec: {(int)rowPerSec}");
        }