-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathTptbm.java
2371 lines (2035 loc) · 75.2 KB
/
Tptbm.java
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown
* at http://oss.oracle.com/licenses/upl
*/
//-----------------------------------------------------------
//
// Tptbm.java
//
// Java version of Tptbm benchmark for measuring scalability
//
//----------------------------------------------------------
import java.sql.*;
import java.io.*;
import java.text.*;
import java.lang.*;
import java.util.*;
import com.timesten.jdbc.*;
class Tptbm
{
// Compilation control
static public final boolean enableScaleout = false;
// class constants
static public final int TPTBM_NONE = -1;
static public final int TPTBM_ORACLE = 0;
static public final int TPTBM_TIMESTEN = 1;
static public final String dfltUsername = "appuser";
static public final int assumedTPS = 100000;
static public final int minHashPages = 40;
static public final int dfltXacts = 10000;
static public final int dfltRamptime = 10;
static public final int dbModeId = -1;
static public final int dbModeNb = -1;
static public final int modeClassic = 0;
static public final int modeScaleout = 1;
static public final int modeScaleoutLocal = 2;
static public final int modeScaleoutRouting = 3;
static public final String dbModeClassicS = "CLASSIC";
static public final String dbModeScaleoutS = "SCALEOUT";
//---------------------------------------------------
// class variables
// All set to a default value, the default values
// can be overwritten using command line options
//---------------------------------------------------
// Number of threads to be run
static public int numThreads = 1;
// Seed for the random number generator
static public int seed = 1;
// Number of transactions each thread runs
static public int numXacts = 0;
// Test duration (measured)
static public int testDuration = 0;
// Ramp time in duration mode
static public int rampTime = -1;
// Percentage of read transactions
static public int reads = 80;
// Percentage of insert transactions
static public int inserts = 0;
// Percentage of insert transactions
static public int updates = 0;
// Percentage of delete transactions
static public int deletes = 0;
// key is used to determine how many
// records to populate in the database.
// key**2 records are initially inserted.
static public int key = 100;
// Min. SQL ops per transaction
static public int min_xact = 1;
// Max. SQL ops per transaction
static public int max_xact = 1;
// 1 insert 3 selects 1 update / xact
static public int multiop = 0;
// Used to turn the Jdbc tracing ON
static public boolean trace = false;
// Used to turn the thread tracing in
// this application ON
static public boolean threadtrace= false;
// Used to specify if database does
// not have to be populated
static public boolean nobuild = false;
static public boolean buildonly = false;
// Should we commit readonly transactions?
static public boolean commitReads = false;
// Used to turn on PrefetchClose ON with client/server
static public boolean prefetchClose = false;
// Verbose mode (undocumented)
static public boolean verbose = false;
// JDBC URL string
static public String url = null;
static public String urlUID = null;
static public String urlPWD = null;
// JDBC defaultDSN string
static public String defaultDSN = tt_version.sample_DSN;
// JDBC user string
static public String username = null;
// JDBC password string
static public String password = null;
// DBMS type
static public int dbms = TPTBM_NONE;
// did the user specify the '-key' parameter
static public boolean fkey = false;
// Range Index
public static boolean range = false;
// PL/SQL
public static boolean usePlsql = false;
// Indicates if we are running in C/S mode
public static boolean isCS = false;
// Indicates if we are connected to a Scaleout database
public static boolean isScaleout = false;
// Run mode
public static int runMode = modeClassic;
// TimesTen Data source
public static TimesTenDataSource ttds = null;
// Total number of replica sets
public static int numReplicaSets = 0;
//--------------------------------------------------
// More class constants
//--------------------------------------------------
public static final String selDbType =
"SELECT paramvalue FROM v$configuration WHERE paramname = 'TTGrid'";
public static final String selDbMode =
"SELECT descr FROM VPN_USERS WHERE vpn_id = " + dbModeId + " AND vpn_nb = " + dbModeNb;
public static final String selNumRs =
"select count(distinct(repset)) from v$distribution_current";
public static final String selRsIds =
"select distinct(repset) rs from v$distribution_current order by rs";
public static final String insertStmt =
"insert into vpn_users values (?,?,?,'0000000000',?)";
public static final String deleteStmt =
"delete from vpn_users where vpn_id = ? and vpn_nb = ?";
//remember to give pages parameter for this statement,
// its calculated based on key
private static final String createStmtHash =
"CREATE TABLE vpn_users(" +
"vpn_id TT_INTEGER NOT NULL," +
"vpn_nb TT_INTEGER NOT NULL," +
"directory_nb CHAR(10) NOT NULL," +
"last_calling_party CHAR(10) NOT NULL," +
"descr CHAR(100) NOT NULL," +
"PRIMARY KEY (vpn_id,vpn_nb)) unique hash on (vpn_id,vpn_nb) pages = ";
private static final String createStmtRange =
"CREATE TABLE vpn_users(" +
"vpn_id TT_INTEGER NOT NULL," +
"vpn_nb TT_INTEGER NOT NULL," +
"directory_nb CHAR(10) NOT NULL," +
"last_calling_party CHAR(10) NOT NULL," +
"descr CHAR(100) NOT NULL," +
"PRIMARY KEY (vpn_id,vpn_nb))";
private static final String distClause =
" distribute by hash(vpn_id, vpn_nb)";
public static final String exec_plsql_stmnt =
"DECLARE " +
"key_cnt number(10); " +
"ins_id number(10); " +
"ins_nb number(10); " +
"multiop number(10); " +
"out_last_calling_party char(10); " +
"sel_directory_nb char(10); " +
"sel_last_calling_party char(10); " +
"sel_descr char(100); " +
"ins_dict char(10); " +
"ins_descr char(100); " +
"rand_id number; " +
"rand_nb number; " +
"rand_last char(10); " +
"begin " +
"key_cnt := :kc; " +
"ins_id := :id; " +
"ins_nb := :nb; " +
"multiop := :multiop; " +
"ins_dict := '55' || ins_id || ins_nb; " +
"ins_descr := '<place holder for description of VPN %d extension %d>' || ins_id || ins_nb; " +
"insert into vpn_users values (ins_id, ins_nb, ins_dict, '0000000000', ins_descr); " +
"for i in 1..3 loop " +
"rand_id := trunc(dbms_random.value(0, key_cnt)); " +
"rand_nb := trunc(dbms_random.value(0, key_cnt)); " +
"select directory_nb, last_calling_party, descr " +
"into sel_directory_nb, sel_last_calling_party, sel_descr " +
"from vpn_users " +
"where vpn_id = rand_id and vpn_nb = rand_nb " +
"and rownum <= 1; " +
"end loop; " +
"rand_id := trunc(dbms_random.value(0, key_cnt)); " +
"rand_nb := trunc(dbms_random.value(0, key_cnt)); " +
"dbms_output.put_line('id: ' || rand_id || ' nb: ' || rand_nb); " +
"out_last_calling_party := rand_id || 'X' || rand_nb; " +
"update vpn_users set last_calling_party = out_last_calling_party " +
"where vpn_id = rand_id and vpn_nb = rand_nb; " +
"if multiop = 2 then " +
"delete from vpn_users " +
"where vpn_id = ins_id and vpn_nb = ins_nb; " +
"end if; " +
"commit; " +
"end;";
public static final String init_plsql_stmnt =
"declare " +
"seed binary_integer; " +
"begin " +
"dbms_random.initialize(seed); " +
"dbms_random.seed(seed); " +
"end;";
//--------------------------------------------------
// Function: main
// Populates the database and instantiate a
// TptbmThreadController object
//--------------------------------------------------
public static void main(String arg[])
{
TptbmThreadController controller;
Connection conn = null;
long elapsedTime;
long totalXacts = 0;
long totalLocates = 0;
long tps;
int tno;
boolean error = false;
// parse arguments
parseArgs(arg);
// Turn the JDBC tracing on
if(Tptbm.trace)
DriverManager.setLogWriter(new PrintWriter(System.out, true));
// Load the JDBC driver
try {
if(dbms == TPTBM_ORACLE) {
Class.forName("oracle.jdbc.OracleDriver");
}
else {
ttds = new TimesTenDataSource();
}
} catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
System.exit(2);
}
System.out.println();
System.out.println("Connecting to the database ...");
// Prompt for the Username and Password
getUsername();
getPassword();
// Connect to the database
try {
if ( dbms == TPTBM_ORACLE ) {
conn = DriverManager.getConnection(Tptbm.url, username, password);
} else {
ttds.setUrl(Tptbm.url);
ttds.setUser(username);
ttds.setPassword(password);
conn = ttds.getConnection();
// check database type
isScaleout = getDbType(conn);
if ( (runMode > modeClassic) && !isScaleout ) {
System.err.println("\n'-scaleout' was specified but database is classic\n");
conn.close();
System.exit(1);
}
}
System.out.println();
System.out.println("Connected to database as " + username + "@" + Tptbm.url);
// Disable auto-commit mode
conn.setAutoCommit(false);
} catch ( SQLException sqe ) {
printSQLException(sqe);
System.exit(2);
}
try {
// populate the database if nobuild option is not specified
if ( ! nobuild )
error = !populate(conn);
if (buildonly || error) {
conn.close();
if ( error )
System.exit(2);
else
System.exit(0);
}
if ( nobuild ) {
error = ! checkDbParams(conn);
if ( error ) {
System.exit(2);
}
}
if ( runMode == modeScaleoutRouting ) {
Statement stmt = conn.createStatement();
ResultSet res = stmt.executeQuery(selNumRs);
if ( !res.next() ) {
System.err.println("Unable to retrieve grid topography");
System.exit(2);
}
numReplicaSets = res.getInt(1);
res.close();
stmt.close();
}
controller = new TptbmThreadController(numThreads, numXacts, testDuration, rampTime);
System.out.println();
System.out.print("Begining execution with " + numThreads + " thread(s): ");
System.out.print(reads + "% read, " + updates + "% update, ");
System.out.print(inserts + "% insert, " + deletes + "% delete");
System.out.println();
error = ! controller.start();
if (!nobuild)
conn.close();
if ( ! error ) {
// Calculate metrics and print
elapsedTime = controller.getElapsedTime();
TptbmThread tth = null;
for (tno = 0; tno < numThreads; tno++) {
tth = controller.getThread(tno);
totalXacts += tth.getTimedXacts();
totalLocates += tth.getLocCycles();
}
tps = (long)(((double)totalXacts/(double)elapsedTime) * 1000.0);
System.out.println();
System.out.print("Elapsed Time: ");
System.out.printf("%9d ms\n", elapsedTime);
System.out.print("Transactions Per Sec: ");
System.out.printf("%9d\n", tps);
if ( verbose && (runMode == modeScaleoutLocal) ) {
double avgLoc = (double)totalLocates / (double)totalXacts;
System.out.print("Average location cycles: ");
System.out.printf("%.3f per operation\n", avgLoc);
}
}
System.out.println("");
} catch ( SQLException e ) {
printSQLException(e);
System.exit(2);
}
System.exit(0);
}
//--------------------------------------------------
// getDbType()
//--------------------------------------------------
static private boolean getDbType(Connection conn) {
Statement stmt = null;
ResultSet res = null;
if ( conn != null )
try {
stmt = conn.createStatement();
res = stmt.executeQuery(selDbType);
if ( res.next() )
if ( res.getInt(1) == 1 )
return true;
} catch ( Exception e ) {
return false;
} finally {
if ( res != null )
try { res.close(); } catch ( Exception e ) { ; }
if ( stmt != null )
try { stmt.close(); } catch ( Exception e ) { ; }
}
return false;
} // getDbType
//--------------------------------------------------
// checkDbParams()
//--------------------------------------------------
static private boolean checkDbParams(Connection conn) {
Statement stmt = null;
ResultSet res = null;
String dbp = null;
String dbm = null;
String dbk = null;
if ( conn != null )
try {
stmt = conn.createStatement();
res = stmt.executeQuery(selDbMode);
if ( res.next() ) {
dbp = res.getString(1);
int i = dbp.indexOf('/');
if ( i >= 0 ) {
dbm = dbp.substring(0,i);
i += 1;
int i2 = dbp.indexOf(' ');
dbk = dbp.substring(i,i2);
i = Integer.parseInt(dbk);
if ( dbm.equals(dbModeClassicS) || dbm.equals(dbModeScaleoutS) ) {
if ( ! Tptbm.fkey ) {
key = i;
return true;
} else {
if ( key == i )
return true;
else
System.err.println("Specified key value " + key +
" differs from value used to create database ("+ dbk + ")");
}
}
}
}
} catch ( Exception e ) {
System.err.println("Error occurred while trying to retrieve benchmark parameters from database.");
return false;
} finally {
if ( res != null )
try { res.close(); } catch ( Exception e ) { ; }
if ( stmt != null )
try { stmt.close(); } catch ( Exception e ) { ; }
}
System.err.println("Benchmark table was not properly populated (missing metadata).");
return false;
} // checkDbParams
//--------------------------------------------------
// usage()
//--------------------------------------------------
static private void usage(boolean full) {
if ( full )
System.err.println(
"\nThis program implements a multi-user throughput benchmark.\n" );
System.err.println(
"Usage:\n\n" +
" Tptbm {-h | -help}\n\n" +
" Tptbm [-url <url_string>] [-threads <num_threads>] [-dbms <dbms_name>]\n" +
" [-multiop | [-read <read%>] [-insert <insert%>] [-delete <delete%>]]\n" +
" [{-xact <xacts> | -sec <seconds> [-ramp <rseconds>]}]\n" +
" [-min <min_xacts>] [-max <max_xacts>] [-seed <seed>]\n" +
//" [-csCommit] [-commitReads] [-range] [-key <keys>] [-plsql]\n" +
" [-commitReads] [-range] [-key <keys>] [-plsql]\n" +
" [-trace] [-nobuild | -build]" );
if ( enableScaleout )
System.err.println(
" [-scaleout [local | routing]]");
System.err.println("");
if ( full ) {
System.err.println(
" -h Prints this message and exits.\n\n" +
" -help Same as -h.\n\n" +
" -url <url_string> Specifies JDBC url string of the database\n" +
" to connect to.\n\n" +
" -threads <num_threads> Specifies the number of concurrent \n" +
" threads. The default is 1.\n\n" +
" -dbms <dbms_name> Use 'timesten' or 'oracle'. 'timesten' is\n" +
" the default.\n\n" +
" -multiop 1 insert, 3 selects, 1 update / transaction.\n\n" +
" -read <read%> Specifies the percentage of read operations.\n" +
" The default is 80.\n\n" +
" -insert <insert%> Specifies the percentage of insert operations.\n" +
" The default is 0. Can't be used with '-sec' or\n" +
" '-nobuild'.\n\n" +
" -delete <delete%> Specifies the percentage of delete operations.\n" +
" The default is 0. Can't be used with '-sec' or\n" +
" '-nobuild'.\n\n" +
" The percentage of updates is 100 minus the read,\n" +
" insert and delete percentages.\n\n" +
" -xact <xacts> Specifies the number of transactions that each\n" +
" thread should execute. The default is " + dfltXacts + ".\n" +
" Mutually exclusive with '-sec'.\n\n" +
" -sec <seconds> Specifies that <seconds> is the test measurement\n" +
" duration. The default is to run in transaction\n" +
" mode (-xact). Mutually exclusive with '-xact'.\n\n" +
" -ramp <rseconds> Specifies that <rseconds> is the ramp up & down\n" +
" time in duration mode (-sec). Default is 10.\n" +
" Mutually exclusive with '-xact'.\n\n" +
" -min <min_xacts> Minimum operations per transaction. Default is 1.\n\n" +
" -max <max_xacts> Maximum operations per transaction. Default is 1.\n\n" +
" The number of operations in each transaction are\n" +
" randomly chosen between min_xacts and max_xacts.\n\n" +
" -seed <seed> Specifies the seed for the random \n" +
" number generator.\n\n" +
//" -csCommit Turn on prefetchClose for client/server. Not\n" +
//" allowed for direct mode connections or when\n" +
//" usign an Oracle database.\n\n" +
" -commitReads By default readonly transactions are not committed,\n" +
" use this option to force them to be committed.\n\n" +
" -range Use a range rather than hash index for the primary key.\n" +
" This is the default when running against an Oracle\n" +
" database. Cannot be used with '-nobuild'.\n\n" +
" -key <keys> Specifies the number of records (squared) to initially\n" +
" populate in the data store. The default for keys is 100.\n" +
" Cannot be used with '-nobuild'.\n\n" +
" -plsql Use PL/SQL for -multiop to reduce round trips.\n\n" +
" -trace Turns JDBC tracing on.\n\n" +
" -nobuild Do not build the table; assumes table exists and is\n" +
" already populated. Cannot be used with '-insert' or\n" +
" '-delete'.\n" );
if ( ! enableScaleout )
System.err.println(
" -build Builds table and exits. Only the '-key' and '-range'\n" +
" parameters are relevant.\n");
else
System.err.println(
" -build Builds table and exits. Only the '-key', '-range' and\n" +
" '-scaleout' parameters are relevant.\n\n" +
" -scaleout Run in Scaleout mode. Creates the table with a hash\n" +
" distribution and adapts runtime behaviour for Scaleout.\n" +
" If not specified then the default is to run in Classic mode.\n" +
" You can run in Classic mode aginst a database built in\n" +
" Scaleout mode but not vice-versa.\n\n" +
" local Use the routing API to constrain all data access to be to\n" +
" rows in the locally connected database element; each thread\n" +
" generates keys that it knows refer to rows in the element\n" +
" that it is connected to. Only relevant at run-time. Cannot\n" +
" be used with '-plsql'.\n\n" +
" routing Use the routing API to optimize data access. Each\n" +
" thread maintains a connection to every database\n" +
" element and uses the routing API to direct operations\n" +
" to an element that it knows contains the target row.\n" +
" Only relevant at run time. Cannot be used with '-multiop',\n" +
" with '-min' or '-max' > 1 or with '-plsql'. Can only be\n" +
" used in client-server mode.\n\n" +
"For the most accurate results, use duration mode (-sec) with a measurement\n" +
"time of at least several minutes and a ramp time of at least 30 seconds.\n"
);
} // full
System.exit(1);
}
//--------------------------------------------------
//
// Function: getConsoleString
//
// Description: Read a String from the console and return it
//
//--------------------------------------------------
static private String getConsoleString (String what) {
String temp = null;
try {
InputStreamReader isr = new InputStreamReader( System.in );
BufferedReader br = new BufferedReader( isr );
temp = br.readLine();
} catch (IOException e)
{
System.out.println();
System.out.println("Problem reading the " + what);
System.out.println();
}
return temp;
}
//--------------------------------------------------
//
// Function: getUsername
//
// Description: Assign the username
//
//--------------------------------------------------
static private void getUsername() {
if ( urlUID == null )
username = dfltUsername;
else
username = urlUID;
}
//--------------------------------------------------
//
// Function: getPassword
//
// Description: Assign the password
//
//--------------------------------------------------
static private void getPassword() {
if ( urlPWD != null )
password = urlPWD;
else
{
String prompt = "Enter password for '" + username + "': ";
password = PasswordField.readPassword(prompt);
}
}
//--------------------------------------------------
//
// Function: populate
//
// Description: Connects to the datastore,
// inserts key**2 records, and disconnects
//
//--------------------------------------------------
static private boolean populate(Connection conn) {
Statement stmt;
PreparedStatement pstmt;
int outerIndex, innerIndex;
int cc = 0;
Timer clock = new Timer();
int pages = ((key*key)/256)+1;
String createStmt = null;
String dist = "";
String dbm = null;
System.out.println();
System.out.println("Populating benchmark database ...");
try {
if (pages < minHashPages) pages = minHashPages;
// if (multiop == 1) {
if (inserts > 0) {
long addpgs;
int avgops = min_xact + ((max_xact - min_xact + 1)/2);
long nx = numXacts;
if ( numXacts <= 0 )
nx = testDuration * assumedTPS;
addpgs = ((numThreads * nx * inserts * avgops) / (256 * 100)) + 1;
pages += addpgs;
}
// Create a Statement object
stmt = conn.createStatement();
// Drop and re-create the table
try {
stmt.executeUpdate("drop table vpn_users");
} catch ( SQLException ex ) { ; }
if ( runMode > modeClassic )
dist = distClause;
if( range )
createStmt = createStmtRange + dist;
else
createStmt = createStmtHash + pages + dist;
stmt.executeUpdate(createStmt);
// Prepare the insert statement
pstmt = conn.prepareStatement(insertStmt);
// Store the database mode and key value
if ( runMode == modeClassic )
dbm = dbModeClassicS;
else
dbm = dbModeScaleoutS;
pstmt.setInt(1,dbModeId);
pstmt.setInt(2,dbModeNb);
pstmt.setString(3," ");
pstmt.setString(4,dbm + "/" + key);
pstmt.executeUpdate();
// commit
conn.commit();
clock.start();
// Insert key**2 records
for(outerIndex = 0; outerIndex < key; outerIndex++)
{
for ( innerIndex = 0; innerIndex < key; innerIndex++)
{
pstmt.setInt(1, outerIndex);
pstmt.setInt(2, innerIndex);
pstmt.setString(3, "55"+(innerIndex%10000)+(outerIndex%10000));
pstmt.setString(4, "<place holder for description of VPN " +
outerIndex + " extension " + innerIndex);
pstmt.executeUpdate();
// commit every 256 rows
cc++;
if ( (cc % 256) == 0)
{
cc = 0;
conn.commit();
}
}
}
// commit
conn.commit();
clock.stop();
stmt.close();
pstmt.close();
long ms = clock.getTimeInMs();
if (ms > 0) {
long tps = (long) ((double)(Tptbm.key*Tptbm.key)/ms * 1000);
System.out.println ("\nDatabase populated with " +
Tptbm.key*Tptbm.key +
" rows in " +
ms + " ms" + " (" +
tps + " TPS)\n");
}
} catch ( SQLException e ) {
printSQLException(e);
return false;
}
return true;
}
//--------------------------------------------------
//
// Function: parseArgs
//
// Parses command line arguments
//
//--------------------------------------------------
private static void parseArgs( String[] args) {
boolean fread = false;
boolean finsert = false;
boolean fdelete = false;
boolean fmin = false;
boolean fmax = false;
boolean fseed = false;
boolean fthreads = false;
int i=0;
// System.out.println("args.length: " + args.length);
while(i<args.length) {
// Command line help
if(args[i].equalsIgnoreCase("-h") ||
args[i].equalsIgnoreCase("-help")) {
usage(true);
}
// JDBC url string
else if(args[i].equalsIgnoreCase("-url")) {
if(++i >= args.length) {
usage(false);
}
if ( url != null )
usage(false);
url = args[i++];
}
// number of threads
else if(args[i].equalsIgnoreCase("-threads")) {
if(++i >= args.length) {
usage(false);
}
if ( fthreads )
usage(false);
fthreads = true;
numThreads = Integer.parseInt(args[i++]);
if(numThreads <= 0) {
System.err.println(
"'-threads' requires a positive, non-zero, integer argument");
System.exit(1);
}
}
// number of transactions for each thread
else if(args[i].equalsIgnoreCase("-xact") || args[i].equalsIgnoreCase("-xacts")) {
if ( (numXacts > 0) || (testDuration > 0) || (rampTime >= 0) ) {
usage(false);
}
if(++i >= args.length) {
usage(false);
}
numXacts = Integer.parseInt(args[i++]);
if(numXacts <= 0) {
System.err.println(
"'-xact' requires a positive, non-zero, integer argument");
System.exit(1);
}
}
// test duration
else if(args[i].equalsIgnoreCase("-sec")) {
if ( (numXacts > 0) || (testDuration > 0) ) {
usage(false);
}
if(++i >= args.length) {
usage(false);
}
testDuration = Integer.parseInt(args[i++]);
if(testDuration <= 0) {
System.err.println(
"'-sec' requires a positive, non-zero, integer argument");
System.exit(1);
}
}
// ramp time
else if(args[i].equalsIgnoreCase("-ramp")) {
if ( (numXacts > 0) || (rampTime >= 0) ) {
usage(false);
}
if(++i >= args.length) {
usage(false);
}
rampTime = Integer.parseInt(args[i++]);
if(rampTime < 0) {
System.err.println(
"'-ramp' requires a positive integer argument");
System.exit(1);
}
}
// seed for random number generator
else if(args[i].equalsIgnoreCase("-seed")) {
if(++i >= args.length) {
usage(false);
}
if ( fseed )
usage(false);
fseed = true;
seed = Integer.parseInt(args[i++]);
if( seed <= 0 ) {
System.err.println(
"'-seed' requires a positive, non-zero, integer argument");
System.exit(1);
}
}
// Percentage of read transactions
else if(args[i].equalsIgnoreCase("-read") || args[i].equalsIgnoreCase("-reads")) {
if(++i >= args.length) {
usage(false);
}
if ( fread || (multiop > 0) )
usage(false);
reads = Integer.parseInt(args[i++]);
if( (reads < 0) || (reads > 100) ) {
System.err.println(
"'-read' requires a positive integer argument <= 100");
System.exit(1);
}
fread = true;
}
// percentage of insert transactions
else if(args[i].equalsIgnoreCase("-insert") || args[i].equalsIgnoreCase("-inserts")) {
if(++i >= args.length) {
usage(false);
}
if ( finsert || (multiop > 0) )
usage(false);
inserts = Integer.parseInt(args[i++]);
if( (inserts < 0) || (inserts > 100) ) {
System.err.println(
"'-insert' requires a positive integer argument <= 100");
System.exit(1);
}
finsert = true;
}
// percentage of delete transactions
else if(args[i].equalsIgnoreCase("-delete") || args[i].equalsIgnoreCase("-deletes")) {
if(++i >= args.length) {
usage(false);
}
if ( fdelete || (multiop > 0) )
usage(false);
deletes = Integer.parseInt(args[i++]);
if( (deletes < 0) || (deletes > 100) ) {
System.err.println(
"'-delete' requires a positive integer argument <= 100");
System.exit(1);
}
fdelete = true;
}
// key to determine number of records to
// insert initially
else if(args[i].equalsIgnoreCase("-key")) {
if(++i >= args.length) {
usage(false);
}
if ( fkey )
usage(false);
if ( nobuild ) {
System.err.println("You cannot specify '-key' with '-nobuild'.");
System.exit(1);
}
fkey = true;
key = Integer.parseInt(args[i++]);
if(key <= 0) {
System.err.println(
"'-key' requires a positive, non-zero, integer argument");
System.exit(1);
}
}
// minimum number of statements/transaction
else if(args[i].equalsIgnoreCase("-min")) {
if(++i >= args.length) {
usage(false);
}
if ( fmin )
usage(false);
fmin = true;
min_xact = Integer.parseInt(args[i++]);