Esempio n. 1
0
        protected string GenerateInsertQuery(int numberOfRecords)
        {
            List <ArrayList> data  = DataGenerator.GetDataRows(numberOfRecords);
            string           query = QueryConstructor.ConstructInsertQuery("t1", data);

            return(query);
        }
Esempio n. 2
0
        protected void SetupForSelect(int size, string table = "t1")
        // populate tables with 500M rows
        {
            single_size   = 4 * size / 10;
            multiple_size = 6 * size / 10;
            ConcurrentQueue <string> cq = new ConcurrentQueue <string>();

            // populate single range
            int batch_size = 1000;

            while (size % batch_size != 0)
            {
                batch_size /= 10;
            }

            for (int i = 0; i < single_size / batch_size; i++)
            {
                string query = QueryConstructor.ConstructInsertQuery(table,
                                                                     DataGenerator.GetDataRowsForSelect(i * batch_size, batch_size: batch_size));
                // execute query
                cq.Enqueue(query);
            }

            while ((multiple_size / conf.multiple) % batch_size != 0)
            {
                batch_size /= 10;
            }
            // populate multiple range
            for (int m = 0; m < conf.multiple; m++)
            {
                for (int i = 0; i < multiple_size / (conf.multiple * batch_size); i++)
                {
                    string query = QueryConstructor.ConstructInsertQuery(table,
                                                                         DataGenerator.GetDataRowsForSelect(single_size + i * batch_size, batch_size: batch_size));
                    // execute query
                    cq.Enqueue(query);
                }
            }

            var watch       = Stopwatch.StartNew();
            var insertCount = 0;

            void startWorker()
            {
                DataBase database = new DataBase();

                while (cq.TryDequeue(out string query))
                {
                    database.ExecuteNonQuery(query);
                    insertCount++;

                    // To keep alive the terminal
                    if (insertCount % 50 == 0)
                    {
                        Console.WriteLine("-");
                    }
                }
                database.Close();
            }

            Parallel.For(0, 5, i => startWorker());

            watch.Stop();
            Console.WriteLine("====Time of INSERT {0} records: {1}====\n", size, watch.Elapsed.ToString(@"hh\:mm\:ss\.fff"));
        }