Program.cs 5.56 KB

using Google.Cloud.Bigtable.Admin.V2;
using Google.Cloud.Bigtable.V2;
using HdrHistogram;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;

namespace Google.Cloud.Bigtable.ScanTest
{
    class Program
    {
        public static AppSettings AppSetting;
        public static int ScanTime;
        public static long ScanCount = 0;
        public static long RecordScanned = 0;
        public static long ThroughputTime = 0;
        public static DateTime _startTime = DateTime.Now;
        public static bool IsDataLoaded = false;

        static void Main(string[] args)
        {
            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Starting Scan test");

            var builder = new ConfigurationBuilder().
                SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            AppSetting = new AppSettings();
            configuration.Bind(AppSetting);            

            V2.TableName _table = new tableHelper().getTable();

            /*string[] arrLimit = AppSetting.ScanLimits.Split(',');
            Hashtable _result = new Hashtable();

            System.Timers.Timer _timer = new System.Timers.Timer();
            _timer = new System.Timers.Timer();
            _timer.Elapsed += _timer_Elapsed;
            _timer.Interval = 60000; //minute

            foreach (string arr in arrLimit)
            {
                if (arr.Trim().Length > 0)
                {
                    if (Convert.ToInt32(arr.Trim()) > 0)
                    {
                        _timer.Enabled = true;                        

                        Program.ScanTime = 0;
                        Program.ThroughputTime = 0;
                        Program.ScanCount = 0;
                        Program.RecordScanned = 0;

                        Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Table {AppSetting.TableName} time interval: {AppSetting.ScanInterval} mins.");

                        new scanHelper(_table).scan(Convert.ToInt32(arr.Trim())).Wait();
                        //_scanResult.Wait();
                        int _throughtput = Convert.ToInt32(Program.RecordScanned / (Program.ThroughputTime / 1000));

                        Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Table {AppSetting.TableName} time interval: {AppSetting.ScanInterval} mins, limit: {arr.Trim()}, throughput time:{_throughtput}.");

                        _result[arr.Trim()] = _throughtput;

                        _timer.Enabled = false;


                    }
                }
            }

            _timer.Stop();
            WriteCsv(_result);
            WriteToConsole(_result);*/

            if (IsDataLoaded)
            {
                Console.WriteLine("");
                Console.WriteLine("");

                Console.WriteLine($"Main thread going to sleep mode for {AppSetting.MutateRowTimeOutInMilliSeconds} milliseconds");
                Thread.Sleep(AppSetting.MutateRowTimeOutInMilliSeconds);
            }

            Environment.Exit(0);

        }

        private static void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - Performed {ScanCount} scans in : {ScanTime + 1} mins, total scanned {RecordScanned} rows, throughput: {ThroughputTime} milliseconds");
            ++ScanTime;
        }

        static void WriteCsv(Hashtable hash)
        {
            try
            {
                using (StreamWriter writetext = new StreamWriter(AppSetting.LogFile))
                {
                    writetext.WriteLine("Number of rows per scan, Throughput");
                    foreach (DictionaryEntry pair in hash)
                    {
                        writetext.WriteLine(pair.Key.ToString() + "," + pair.Value.ToString());
                    }
                    writetext.WriteLine("");
                    writetext.WriteLine("");
                    writetext.WriteLine("Client, Type, StartTime");
                    writetext.WriteLine($"C#, scant, {_startTime.ToString("yyyy-MM-dd HH:mm:ss")}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Exception writing test results into {AppSetting.LogFile },error: {ex.Message}");
            }
        }

        static void WriteToConsole(Hashtable hash)
        {
            try
            {
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("---------------------RESULT--------------------");
                Console.WriteLine("Number of rows per scan, Throughput");
                foreach (DictionaryEntry pair in hash)
                {
                    Console.WriteLine(pair.Key.ToString() + "," + pair.Value.ToString());
                }
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("Client, Type, StartTime");
                Console.WriteLine($"C#, scant, {_startTime.ToString("yyyy-MM-dd HH:mm:ss")}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} Exception writing test results into {AppSetting.LogFile },error: {ex.Message}");
            }
        }
    }
}