@@ -36,40 +36,39 @@ This code sample simulates an IoT Smart Grid scenario where multiple IoT power m
36
36
shock absorber scenario: https://blogs.technet.microsoft.com/dataplatforminsider/2013/09/19/in-memory-oltp-common-design-pattern-high-data-input-rateshock-absorber/.
37
37
Every async task in the Data Generator produces a batch of records with random values in order to simulate the data of an IoT power meter.
38
38
It then calls a natively compiled stored procedure, that accepts an memory optimized table valued parameter (TVP), to insert the data into an memory optimized SQL Server table.
39
- In addition to the in-memory features, the sample is leveraging System-Versioned Temporal Tables: https://msdn.microsoft.com/en-us/library/dn935015.aspx for building version history,
40
- Clustered Columnstore Index: https://msdn.microsoft.com/en-us/library/dn817827.aspx) for enabling real time operational analytics, and
39
+ In addition to the in-memory features, the sample is offloading historical values to a Clustered Columnstore Index: https://msdn.microsoft.com/en-us/library/dn817827.aspx) for enabling real time operational analytics, and
41
40
Power BI: https://powerbi.microsoft.com/en-us/desktop/ for data visualization.
42
41
*/
43
42
namespace ConsoleClient
44
43
{
45
44
class Program
46
45
{
47
46
static SqlDataGenerator dataGenerator ;
48
- static string connection ;
47
+ static string [ ] connection ;
49
48
static string spName ;
50
49
static string logFileName ;
51
50
static string powerBIDesktopPath ;
52
- static int tasks ;
53
51
static int meters ;
54
52
static int batchSize ;
55
- static int delay ;
56
53
static int commandTimeout ;
57
- static int shockFrequency ;
58
- static int shockDuration ;
59
- static int rpsFrequency ;
60
- static int enableShock ;
61
- static Timer mainTimer = new Timer ( ) ;
54
+ static int rpsFrequency ;
55
+ static int numberOfDataLoadTasks ;
56
+ static int numberOfOffLoadTasks ;
57
+ static int deleteBatchSize ;
58
+ static string deleteSPName ;
59
+ static int dataLoadCommandDelay ;
60
+ static int offLoadCommandDelay ;
61
+ static int delayStart ;
62
+ static int appRunDuration ;
63
+ static int numberOfRowsOfloadLimit ;
62
64
static Timer rpsTimer = new Timer ( ) ;
63
- static Timer shockTimer = new Timer ( ) ;
64
65
65
66
static void Main ( string [ ] args )
66
67
{
67
68
Init ( ) ;
68
- dataGenerator = new SqlDataGenerator ( connection , spName , commandTimeout , meters , tasks , delay , batchSize , ExceptionCallback ) ;
69
-
70
- mainTimer . Elapsed += mainTimer_Tick ;
69
+ dataGenerator = new SqlDataGenerator ( connection , spName , commandTimeout , meters , numberOfDataLoadTasks , dataLoadCommandDelay , batchSize , deleteSPName , numberOfOffLoadTasks , offLoadCommandDelay , deleteBatchSize , numberOfRowsOfloadLimit , ExceptionCallback ) ;
71
70
rpsTimer . Elapsed += rpsTimer_Tick ;
72
- shockTimer . Elapsed += shockTimer_Tick ;
71
+
73
72
74
73
string commandString = string . Empty ;
75
74
Console . ForegroundColor = ConsoleColor . White ;
@@ -129,9 +128,7 @@ static async void Start()
129
128
{
130
129
if ( ! dataGenerator . IsRunning )
131
130
{
132
- if ( enableShock == 1 ) mainTimer . Start ( ) ;
133
131
rpsTimer . Start ( ) ;
134
-
135
132
await dataGenerator . RunAsync ( ) ;
136
133
}
137
134
}
@@ -144,10 +141,7 @@ static async void Stop()
144
141
{
145
142
if ( dataGenerator . IsRunning )
146
143
{
147
- if ( enableShock == 1 ) mainTimer . Stop ( ) ;
148
144
rpsTimer . Stop ( ) ;
149
- if ( enableShock == 1 ) shockTimer . Stop ( ) ;
150
-
151
145
await dataGenerator . StopAsync ( ) ;
152
146
dataGenerator . RpsReset ( ) ;
153
147
}
@@ -177,47 +171,47 @@ static void Init()
177
171
{
178
172
try
179
173
{
174
+ int numberOfSqlConnections = ConfigurationManager . ConnectionStrings . Count ;
175
+ connection = new string [ numberOfSqlConnections ] ;
180
176
// Read Config Settings
181
- connection = ConfigurationManager . ConnectionStrings [ "Db" ] . ConnectionString ;
177
+ for ( int i = 0 ; i < numberOfSqlConnections ; i ++ )
178
+ {
179
+ connection [ i ] = ConfigurationManager . ConnectionStrings [ i ] . ConnectionString ;
180
+ }
181
+
182
182
spName = ConfigurationManager . AppSettings [ "insertSPName" ] ;
183
183
logFileName = ConfigurationManager . AppSettings [ "logFileName" ] ;
184
- powerBIDesktopPath = ConfigurationManager . AppSettings [ "powerBIDesktopPath" ] ;
185
- tasks = int . Parse ( ConfigurationManager . AppSettings [ "numberOfTasks" ] ) ;
186
- meters = int . Parse ( ConfigurationManager . AppSettings [ "numberOfMeters" ] ) ;
184
+ numberOfDataLoadTasks = int . Parse ( ConfigurationManager . AppSettings [ "numberOfDataLoadTasks" ] ) ;
185
+ dataLoadCommandDelay = int . Parse ( ConfigurationManager . AppSettings [ "dataLoadCommandDelay" ] ) ;
187
186
batchSize = int . Parse ( ConfigurationManager . AppSettings [ "batchSize" ] ) ;
188
- delay = int . Parse ( ConfigurationManager . AppSettings [ "commandDelay" ] ) ;
187
+ deleteSPName = ConfigurationManager . AppSettings [ "deleteSPName" ] ;
188
+ numberOfOffLoadTasks = int . Parse ( ConfigurationManager . AppSettings [ "numberOfOffLoadTasks" ] ) ;
189
+ offLoadCommandDelay = int . Parse ( ConfigurationManager . AppSettings [ "offLoadCommandDelay" ] ) ;
190
+ deleteBatchSize = int . Parse ( ConfigurationManager . AppSettings [ "deleteBatchSize" ] ) ;
191
+ meters = int . Parse ( ConfigurationManager . AppSettings [ "numberOfMeters" ] ) ;
189
192
commandTimeout = int . Parse ( ConfigurationManager . AppSettings [ "commandTimeout" ] ) ;
190
- shockFrequency = int . Parse ( ConfigurationManager . AppSettings [ "shockFrequency" ] ) ;
191
- shockDuration = int . Parse ( ConfigurationManager . AppSettings [ "shockDuration" ] ) ;
192
- enableShock = int . Parse ( ConfigurationManager . AppSettings [ "enableShock" ] ) ;
193
-
193
+ delayStart = int . Parse ( ConfigurationManager . AppSettings [ "delayStart" ] ) ;
194
+ appRunDuration = int . Parse ( ConfigurationManager . AppSettings [ "appRunDuration" ] ) ;
194
195
rpsFrequency = int . Parse ( ConfigurationManager . AppSettings [ "rpsFrequency" ] ) ;
196
+ numberOfRowsOfloadLimit = int . Parse ( ConfigurationManager . AppSettings [ "numberOfRowsOfloadLimit" ] ) ;
197
+ powerBIDesktopPath = ConfigurationManager . AppSettings [ "powerBIDesktopPath" ] ;
195
198
196
199
// Initialize Timers
197
- mainTimer . Interval = shockFrequency ;
198
- shockTimer . Interval = shockDuration ;
199
200
rpsTimer . Interval = rpsFrequency ;
200
201
201
202
if ( batchSize <= 0 ) throw new SqlDataGeneratorException ( "The Batch Size cannot be less or equal to zero." ) ;
202
203
203
- if ( tasks <= 0 ) throw new SqlDataGeneratorException ( "Number Of Tasks cannot be less or equal to zero." ) ;
204
+ if ( numberOfDataLoadTasks <= 0 ) throw new SqlDataGeneratorException ( "Number Of Tasks cannot be less or equal to zero." ) ;
204
205
205
- if ( delay < 0 ) throw new SqlDataGeneratorException ( "Delay cannot be less than zero" ) ;
206
+ if ( dataLoadCommandDelay < 0 ) throw new SqlDataGeneratorException ( "Delay cannot be less than zero" ) ;
206
207
207
208
if ( meters <= 0 ) throw new SqlDataGeneratorException ( "Number Of Meters cannot be less than zero" ) ;
208
209
209
- if ( meters < batchSize * tasks ) throw new SqlDataGeneratorException ( "Number Of Meters cannot be less than (Tasks * BatchSize)." ) ;
210
+ if ( meters < batchSize * numberOfDataLoadTasks ) throw new SqlDataGeneratorException ( "Number Of Meters cannot be less than (Tasks * BatchSize)." ) ;
211
+
210
212
}
211
213
catch ( Exception exception ) { HandleException ( exception ) ; }
212
214
}
213
- static void mainTimer_Tick ( object sender , ElapsedEventArgs e )
214
- {
215
- if ( dataGenerator . IsRunning )
216
- {
217
- dataGenerator . Delay = 0 ;
218
- shockTimer . Start ( ) ;
219
- }
220
- }
221
215
static void rpsTimer_Tick ( object sender , ElapsedEventArgs e )
222
216
{
223
217
try
@@ -236,11 +230,5 @@ static void rpsTimer_Tick(object sender, ElapsedEventArgs e)
236
230
}
237
231
catch ( Exception exception ) { HandleException ( exception ) ; }
238
232
}
239
- static void shockTimer_Tick ( object sender , ElapsedEventArgs e )
240
- {
241
- Random rand = new Random ( ) ;
242
- dataGenerator . Delay = rand . Next ( 1500 , 3000 ) ;
243
- shockTimer . Stop ( ) ;
244
- }
245
233
}
246
234
}
0 commit comments