Program.cs
5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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}");
}
}
}
}