-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPerfTools.RanWrite.xml
More file actions
1123 lines (964 loc) · 30.9 KB
/
PerfTools.RanWrite.xml
File metadata and controls
1123 lines (964 loc) · 30.9 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
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
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="IRIS" version="26" zv="IRIS for UNIX (Ubuntu Server LTS for ARM64 Containers) 2024.1 (Build 263U)" ts="2024-05-03 20:11:39">
<Class name="PerfTools.RanWrite">
<Description><![CDATA[
Random write test
There is a tstart and tcommit around each set, so to test journal synchs on ECP this can be run on an application server. The IO will still be on the DB server, but ECP and (high) journal synchs should be tested.
ranwrite uses very little CPU (<1%) so could be run with RANREAD for a r/w smoke test. Adjust the pacing for the expected load.]]></Description>
<Super>%Persistent</Super>
<TimeChanged>66963,72584.178341343</TimeChanged>
<TimeCreated>65488,66744.147036</TimeCreated>
<Parameter name="EXPORTFILENAME">
<Default>PerfToolsRanWrite_</Default>
</Parameter>
<Parameter name="FILEEXTENSION">
<Default>.txt</Default>
</Parameter>
<Parameter name="DELIM">
<Expression>$char(44)</Expression>
</Parameter>
<Parameter name="TIMEDECIMAL">
<Default>4</Default>
</Parameter>
<Property name="RunDate">
<Description>
Date this run was started
RunDate and RunTime uniquely identify a run</Description>
<Type>%Date</Type>
</Property>
<Property name="RunTime">
<Description>
Time this run was started
RunDate and RunTime uniquely identify a run</Description>
<Type>%Time</Type>
</Property>
<Property name="Batch">
<Description>
Run number</Description>
<Type>%Integer</Type>
</Property>
<Property name="Database">
<Description>
Database directory used for the random read test</Description>
<Type>%String</Type>
</Property>
<Property name="Namespace">
<Description>
Namespace used for the random write test</Description>
<Type>%String</Type>
</Property>
<Property name="Processes">
<Description>
Number of processes</Description>
<Type>%Integer</Type>
</Property>
<Property name="Job">
<Description>
Job number</Description>
<Type>%Integer</Type>
</Property>
<Property name="Reads">
<Description>
Number of reads</Description>
<Type>%Integer</Type>
</Property>
<Property name="Writes">
<Description>
Number of writes</Description>
<Type>%Integer</Type>
</Property>
<Property name="ReadsPerSec">
<Description>
Number of reads</Description>
<Type>%Integer</Type>
</Property>
<Property name="WritesPerSec">
<Description>
Number of writes</Description>
<Type>%Integer</Type>
</Property>
<Property name="ProcTime">
<Description>
Worker job runtime</Description>
<Type>%Time</Type>
</Property>
<Property name="ReadPct">
<Description>
Read pct</Description>
<Type>%Integer</Type>
</Property>
<Method name="Help">
<Description>
Display help</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
#dim str as %String
// write display title
set str=" - "
write !,"do ##class(PerfTools.RanWrite).Setup(Directory,DatabaseName)"
write !,str_"Creates database and namespace with the same name."
write !,"do ##class(PerfTools.RanWrite).CreateGlobals(Directory,NumGlobals,NumSubscripts)"
write !,str_"Creates the requested numbered subscripts (1-N) under the globals ^RanWriteGlobal1,"
write !,str_"^RanWriteGlobal2, etc. Default 5 globals, 1M subscripts each."
write !,"do ##class(PerfTools.RanWrite).AddGlobals(Directory,NumGlobals,NumSubscripts)"
write !,str_"Creates more Globals if needed after the initial creation is done."
write !,str_"NumSubscripts is optional in this case, since by default it will take the size of ^RanWriteGlobal1"
write !,"do ##class(PerfTools.RanWrite).CountSubscripts(Directory)"
write !,str_"Counts (via $order) the number of subscripts in ^RanWriteGlobal* in the indicated directory."
write !,"do ##class(PerfTools.RanWrite).GetSizes(Directory)"
write !,str_"Outputs as CSV the number of globals and number of subscripts in ^RanWriteGlobal* in the indicated directory."
write !,"do ##class(PerfTools.RanWrite).Run(Directory,NumProcs,RunTime (sec),TransactionLength,HangTime (ms))"
write !,str_"Run the random write IO test. All parameters other than the directory have defaults."
write !,"do ##class(PerfTools.RanWrite).Stop()"
write !,str_"Terminates all background jobs."
write !,"do ##class(PerfTools.RanWrite).Reset()"
write !,str_"Deletes statistics of prior runs."
write !,"do ##class(PerfTools.RanWrite).Purge(Directory)"
write !,str_"Deletes namespace and database of the same name."
write !,"do ##class(PerfTools.RanWrite).Export(Directory)"
write !,str_"Exports a summary of all random write test history to comma delimited text file."
]]></Implementation>
</Method>
<Method name="Setup">
<Description>
Create database and namespace for random write test</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>Directory:%String,Name:%String="ZRanWrite"</FormalSpec>
<Implementation><![CDATA[
if $g(Name)="" quit 0
set tSC=$$$OK
Try {
set currNS=$namespace
zn "%SYS"
//create resource
set Resource="%DB_"_Name
if ##class(Security.Resources).Exists(Resource)=0 {
set tSC=##class(Security.Resources).Create(Resource,"resource for "_Name,0,2)
If $$$ISERR(tSC) {
Set msg = Resource_": "_"Could not create this resource."
Set tSC = $$$ERROR($$$ObjectScriptError,msg)
Throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
}
Set Directory = $zstrip(Directory,"<>W")
Set tSC = ##class(%File).CreateDirectoryChain(Directory)
If $$$ISERR(tSC) {
Set msg = Directory_": "_"Could not create this directory. Please check the directory and try again."
Set tSC = $$$ERROR($$$ObjectScriptError,msg)
Throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
Set tSC = ##class(SYS.Database).CreateDatabase(Directory,,,,Resource)
If $$$ISERR(tSC) throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
//update cpf with DB
if ##class(Config.Databases).Exists(Name,.oref)=1 {
set dir=##class(%File).NormalizeDirectory(Directory)
set dir=$zconvert(dir,"L")
if $zconvert(oref.Directory,"L")'=dir {
Set msg = Name_": "_"Database already exists but with different directory"
Set tSC = $$$ERROR($$$ObjectScriptError,msg)
throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
}
else {
Set Properties("Directory") = Directory
Set tSC =##class(Config.Databases).Create(Name,.Properties)
If $$$ISERR(tSC) throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
//mount the db
set tSC= ##class(SYS.Database).MountDatabase(Directory)
If $$$ISERR(tSC) {
kill err
if $system.Status.GetErrorText(tSC)="ERROR #19: the file was already mounted" {
set tSC=1
}
else {
Throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
}
}
Set nsProperties("Globals") = Name
Set nsProperties("Library") = "IRISLIB"
Set nsProperties("Routines") = Name
Set nsProperties("SysGlobals") = "IRISSYS"
Set nsProperties("SysRoutines") = "IRISSYS"
Set nsProperties("TempGlobals") = "IRISTEMP"
Set tSC = ##Class(Config.Namespaces).Create(Name,.nsProperties)
if $system.Status.GetErrorText(tSC)="ERROR #419: Namespace ABCF already exists" set tSC=1
If $$$ISERR(tSC) throw ##Class(%Exception.StatusException).CreateFromStatus(tSC)
zn currNS
}
catch exp {
zn currNS
use 0 write !, exp.Name
}
zn currNS
quit tSC
]]></Implementation>
</Method>
<Method name="setDatabaseSize">
<ClassMethod>1</ClassMethod>
<FormalSpec>directory:%String,size:%Integer,expansionSize:%Integer</FormalSpec>
<Implementation><![CDATA[
if $g(directory)="" quit 0
if $g(size,0)=0 quit 0
set currNS=$namespace
zn "%SYS"
set db=##class(SYS.Database).%OpenId(directory)
if db="" {
do $System.OBJ.DisplayError(%objlasterror)
set tSC=0
}
else {
set db.Size=size
set db.ExpansionSize=expansionSize
set tSC=db.%Save()
if 'tSC do $System.OBJ.DisplayError(tSC)
}
zn currNS
quit tSC
]]></Implementation>
</Method>
<Method name="IsValidDatabaseDir">
<Description>
Return true if database directory is valid</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
#dim found as %Boolean = '$$$OK
#dim dbDir as %String
#dim rs as %ObjectHandle
//Switch to %SYS namespace
New $NAMESPACE
set $NAMESPACE="%SYS"
//If directory exists
if ##class(%Library.File).DirectoryExists(pDirectory) {
//Loop through all databases
set rs=##class(%Library.ResultSet).%New("Config.Databases:LocalDatabaseList")
do rs.Execute("*")
while rs.Next() {
set dbDir=rs.Data("Directory")
set dbDir=##class(%Library.File).NormalizeDirectory(dbDir)
//If directory exists
if pDirectory=dbDir {
set found=$$$OK
quit
}
}
}
quit found
]]></Implementation>
</Method>
<Method name="Purge">
<Description>
Delete database and namespace for random write test</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String,pDBname:%String="ZRanWrite"</FormalSpec>
<Implementation><![CDATA[
#dim directory,dbName as %String = ""
#dim dbObj as %ObjectHandle
//Switch to %SYS namespace
New $NAMESPACE
set $NAMESPACE="%SYS"
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Convert database name to UPPER case
set dbName=$zconvert(pDBname,"U")
//Check if directory exists
if '(##class(%Library.File).DirectoryExists(directory)) {
w !,"Error: Directory "_directory_" does not exist!"
quit
}
//Check if database exists
if '(##Class(Config.Databases).Exists(dbName,.dbObj)) {
w !,"Error: Database "_dbName_" does not exist!"
quit
}
try {
set Status=##Class(SYS.Database).DismountDatabase(directory)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
return
}
set Status=##Class(SYS.Database).DeleteDatabase(directory)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
return
}
set Status=##Class(Config.Namespaces).Delete(dbName)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
return
}
set Status=##Class(Config.Databases).Delete(dbName)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
return
}
set args=2
set args(1)="-Rf"
set args(2)=directory
do $ZF(-100,"","rm",.args)
}
catch {}
]]></Implementation>
</Method>
<Method name="CreateGlobals">
<Description>
Pre-create a few top-level globals with some number of pre-existing subscripts</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String="",pNumGlobals:%Integer=5,pNumSubscripts:%Integer=1000000</FormalSpec>
<Implementation><![CDATA[
#dim directory,db as %String
try {
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Check if database exists
if ..IsValidDatabaseDir(directory) {
set return = $NAMESPACE
zn "%SYS"
// Find the DB associated with the directory
set Status=##Class(Config.Databases).DatabasesByDirectory("",directory,.dblist)
if '$$$ISOK(Status) {
write "Error="_$SYSTEM.Status.GetErrorText(Status)
zn return
return
}
zn return
//Convert database name to UPPER case
set namespace=$zconvert(dblist,"U")
set namespace=$zstrip(namespace,"<>WPC")
write "Starting global creation."
//For each global, job off a separate process to create it
for i=1:1:pNumGlobals {
set pre = $ZCHILD
job ..CreateGlobalsMain(namespace,i,pNumSubscripts)
set post = $ZCHILD
if (pre'=post) {
set ^PerfTools.RanWrite("JOBLIST",$j,i)=post
}
}
//Loop while background jobs are running
set timer=0
do {
set currentJobs=..CountJobs()
if timer>29 set timer = 0 write "."
hang 1
set timer = timer + 1
} while currentJobs>0
zn namespace
set ^RanWriteGlobalCount=pNumGlobals
zn return
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
]]></Implementation>
</Method>
<Method name="AddGlobals">
<Description>
Pre-create a few top-level globals with some number of pre-existing subscripts</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String="",pNumGlobals:%Integer=5,pNumSubscripts:%Integer=0</FormalSpec>
<Implementation><![CDATA[
#dim directory,db as %String
#dim numGlobals,numSubscripts as %Integer
try {
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Check if database exists
if ..IsValidDatabaseDir(directory) {
set return = $NAMESPACE
zn "%SYS"
// Find the DB associated with the directory
set Status=##Class(Config.Databases).DatabasesByDirectory("",directory,.dblist)
if '$$$ISOK(Status) {
write "Error="_$SYSTEM.Status.GetErrorText(Status)
zn return
return
}
zn return
//Convert database name to UPPER case
set namespace=$zconvert(dblist,"U")
set namespace=$zstrip(namespace,"<>WPC")
zn namespace
if '$data(^RanWriteGlobalCount) {
write "The global ^RanWriteGlobalCount is not present in the chosen database.",!,"Make sure you have run the CreateGlobals function prior to Run."
zn return
return
}
set numGlobals = ^RanWriteGlobalCount
if (numGlobals >= pNumGlobals) {
write "There are already "_numGlobals_" Globals present."
zn return
return
}
set diff = pNumGlobals - numGlobals
write "Filling "_diff_" new Globals, starting with number "_(numGlobals+1)
set numSubscripts = pNumSubscripts
if (numSubscripts = 0) {
set numSubscripts = $number(^RanWriteGlobal1("Size"))
}
write !,"Number of subscripts is "_numSubscripts
zn return
write !,"Starting global creation."
//For each global, job off a separate process to create it
for i=numGlobals+1:1:pNumGlobals {
set pre = $ZCHILD
job ..CreateGlobalsMain(namespace,i,numSubscripts)
set post = $ZCHILD
if (pre'=post) {
set ^PerfTools.RanWrite("JOBLIST",$j,i)=post
}
}
//Loop while background jobs are running
set timer=0
do {
set currentJobs=..CountJobs()
if timer>29 set timer = 0 write "."
hang 1
set timer = timer + 1
} while currentJobs>0
zn namespace
set ^RanWriteGlobalCount=pNumGlobals
zn return
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
]]></Implementation>
</Method>
<Method name="CreateGlobalsMain">
<ClassMethod>1</ClassMethod>
<FormalSpec>pNameSpace:%String,pGlobal:%Integer,pNumSubscripts:%Integer</FormalSpec>
<Implementation><![CDATA[
zn pNameSpace
set var = "^RanWriteGlobal"_pGlobal
if ($data(@var)) {
kill @var
}
set @var="Created by job "_$JOB_" at "_$ztime($piece($h,",",2))_" on "_$zdate(+$h)
// Create initial subscripts
for index=1:1:pNumSubscripts {
set location = var_"("_index_")"
set @location = "Created by job "_$JOB_" at "_$ztime($piece($h,",",2))_" on "_$zdate(+$h)
}
set location = var_"("_"""Size"""_")"
set @location = pNumSubscripts
]]></Implementation>
</Method>
<Method name="CountSubscripts">
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String=""</FormalSpec>
<Implementation><![CDATA[
try {
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Check if database exists
if ..IsValidDatabaseDir(directory) {
set return = $NAMESPACE
zn "%SYS"
// Find the DB associated with the directory
set Status=##Class(Config.Databases).DatabasesByDirectory("",directory,.dblist)
if '$$$ISOK(Status) {
write "Error="_$SYSTEM.Status.GetErrorText(Status)
zn return
return
}
//Convert database name to UPPER case
set namespace=$zconvert(dblist,"U")
set namespace=$zstrip(namespace,"<>WPC")
zn namespace
set total = 0
if '$data(^RanWriteGlobalCount) {
write "The global ^RanWriteGlobalCount is not present in the chosen database.",!,"Make sure you have run the CreateGlobals function prior to Run."
zn return
return
}
set numGlobals = ^RanWriteGlobalCount
write "Number of Globals is: "_numGlobals
for i=1:1:numGlobals {
set count = 0
set start = "^RanWriteGlobal"_i_"("_""""""_")"
set key=$ORDER(@start)
while (key'="") {
// Get next subscript
if (key'="Size"){
set location="^RanWriteGlobal"_i_"("_key_")"
} else {
set location="^RanWriteGlobal"_i_"("_"""Size"""_")"
}
set key = $ORDER(@location)
set count = count + 1
}
// Return one fewer than the counted total because the "Size" variable also exists
write !,"Number of subscripts in ^RanWriteGlobal"_i_" is: "_(count-1)
set total = total + (count - 1)
}
write !,"Number of subscripts in all globals is: "_total
zn return
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
]]></Implementation>
</Method>
<Method name="GetSizes">
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String=""</FormalSpec>
<Implementation><![CDATA[
#dim directory,db as %String
try {
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Check if database exists
if ..IsValidDatabaseDir(directory) {
set return = $NAMESPACE
zn "%SYS"
// Find the DB associated with the directory
set Status=##Class(Config.Databases).DatabasesByDirectory("",directory,.dblist)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
zn return
return
}
zn return
//Convert database name to UPPER case
set namespace=$zconvert(dblist,"U")
set namespace=$zstrip(namespace,"<>WPC")
zn namespace
if '$data(^RanWriteGlobalCount) {
write !, "The global ^RanWriteGlobalCount is not present in the chosen database.",!,"Make sure you have run the CreateGlobals function prior to Run."
zn return
return
}
set numGlobals = ^RanWriteGlobalCount
write !,numGlobals
for i=1:1:numGlobals {
set var = "^RanWriteGlobal"_i
if ($data(@var)) {
set var = "^RanWriteGlobal"_i_"("_"""Size"""_")"
w ","_@var
}
else {
w ",NA"
}
}
zn return
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
]]></Implementation>
</Method>
<Method name="Run">
<Description><![CDATA[
do ##class(PerfTools.RanWrite).Run(<directory>,<number of procs>,<run time in seconds>,<number of writes per transaction>,<hang time in milliseconds>)
do ##class(PerfTools.RanWrite).Run("/ISC/tests/TMP",10,30,50,0.5)]]></Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String="",pProcesses:%Integer=1,pRunTime:%Integer=300,pTransactionLength:%Integer=50,pHang:%Float=2</FormalSpec>
<Implementation><![CDATA[
#dim tSC as %Status = $$$OK
#dim directory,db as %String
#dim h,date,time as %String
#dim i,batch,currentJobs as %Integer
#dim respTime as %Double
try {
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Check if database exists
if ..IsValidDatabaseDir(directory) {
set return = $NAMESPACE
zn "%SYS"
// Find the DB associated with the directory
set Status=##Class(Config.Databases).DatabasesByDirectory("",directory,.dblist)
if '$$$ISOK(Status) {
write !,"Error="_$SYSTEM.Status.GetErrorText(Status)
zn return
return
}
//Convert database name to UPPER case
set namespace=$zconvert(dblist,"U")
set namespace=$zstrip(namespace,"<>WPC")
zn namespace
set total = 0
if '$data(^RanWriteGlobalCount) {
write !, "The variable ^RanWriteGlobalCount is not present in the chosen database.",!,"Make sure you have run the CreateGlobals function prior to Run."
zn return
return
}
set numGlobals = ^RanWriteGlobalCount
write !,"Number of Globals is: "_numGlobals
if (numGlobals < pProcesses) {
write !,"There are insufficient Globals to run "_pProcesses_" jobs."
write !,"Please either reduce the number of jobs to "_numGlobals_" or fewer, or run AddGlobals to make up the difference."
zn return
return
}
for i=1:1:numGlobals {
set var = "^RanWriteGlobal"_i_"("_"""Size"""_")"
set count = @var
//write !,"Number of subscripts in ^RanWriteGlobal"_i_" is: "_count
set total = total + count
}
write !,"Total number of subscripts in all globals is: "_total
zn return
//Each run is identified by the start date / time to keep related items together.
set h=$horolog
set date=+h
set time=$piece(h,",",2)
set batch=$increment(^PerfTools.RanWrite("BATCH"))
write !,"RanWrite process ",$JOB," creating "_pProcesses_" worker processes in the background."
//Set run flag to zero - don't start running until all jobs created
set ^PerfTools.RanWrite("RUNSTATUS")=0
//For each process
for i=1:1:pProcesses {
//Job off separate processes to perform random write test
set pre = $ZCHILD
job ..RanWriteJob(date,time,batch,directory,namespace,pRunTime,pTransactionLength,pHang,i,pProcesses)
set post = $ZCHILD
if (pre'=post) {
set ^PerfTools.RanWrite("JOBLIST",$j,i)=post
//w !," Prepped RanWriteJob ",$ZCHILD," for parent ",$JOB," as element",i
}
}
write !,"Starting "_pProcesses_" processes for RanWrite job number ",$JOB
//Start all jobs
set ^PerfTools.RanWrite("RUNSTATUS")=$$$OK /// This sets it to 1
write !,"To terminate run: do ##class(PerfTools.RanWrite).Stop()"
write !,"Waiting to finish."
//Loop while background jobs are running
set timer=0
do {
set currentJobs=..CountJobs()
if timer>29 set timer = 0 write "."
hang 1
set timer = timer + 1
} while currentJobs>0
write !,"Random write background jobs finished for parent ",$JOB
//Get totals
set WPS=..GetTotalWritesPerSec(batch)
write !,"RanWrite job ",$JOB,"'s ",pProcesses_" processes total total writes/s = "_WPS
} else {
write !,"ERROR: Directory not valid. Call the following for help:"
write !,"do ##class(PerfTools.RanWrite).Help()"
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
if (^PerfTools.RanWrite("RUNSTATUS")='$$$OK) { // This is what Stop sets it to
if ('$SYSTEM.Process.IsProgrammerMode()) {
do $zu(4,$j,1) h 0
}
}
]]></Implementation>
</Method>
<Method name="RanWriteJob">
<ClassMethod>1</ClassMethod>
<FormalSpec>pDate:%Date,pTime:%Time,pBatch:%Integer,pDirectory:%String,pNamespace:%String,pRunTime:%Integer,pTransactionLength:%Integer,pHang:%Float,pJobNum:%Integer,pNumProcesses:%Integer</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
#dim db as %String
#dim i,numGlobals,total,index,count as %Integer
#dim startTime,endTime,elapseTime as %String
try {
set home = $NAMESPACE
zn pNamespace
//Loop until ready to go
for i=1:1 {
//Wait one second
hang 1
//Exit loop when run when status is ok
quit:^[home]PerfTools.RanWrite("RUNSTATUS")=$$$OK
}
set writes = 0
set numGlobals = ^RanWriteGlobalCount
set startTime=$ztimestamp
set start = $p(startTime,",",2)
set end = start + pRunTime
///set loremipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
while (^[home]PerfTools.RanWrite("RUNSTATUS")'=0) {
// Choose which global to update for this transaction
//set global = $random(numGlobals)+1 // This randomization removed to stop collisions
set global = pJobNum
set var = "^RanWriteGlobal"_global_"("_"""Size"""_")"
set count = @var
tstart
for i=1:1:pTransactionLength {
set index = $random(count)+1
set var = "^RanWriteGlobal"_global_"("_index_")"
set @var = "Updated by job "_$JOB_" at "_$ztime($piece($h,",",2))_" on "_$zdate(+$h) ///_" "_loremipsum
}
tcommit
set writes = writes + pTransactionLength
//hang pHang/1000 // Input is in milliseconds, hang in seconds
d $zu(136,27,pHang*1000000) // Input is in milliseconds, $zu command in nanoseconds
//Exit loop if time is up
quit:($p($ztimestamp,",",2) > end)
}
set endTime=$ztimestamp
set elapseTime=$p(endTime,",",2)-$p(startTime,",",2)
zn home
//Save job info
set tObj=..%New()
set tObj.RunDate=pDate
set tObj.RunTime=pTime
set tObj.Batch=pBatch
set tObj.Job=pJobNum
set tObj.Database=pDirectory
set tObj.Namespace=pNamespace
set tObj.Writes=writes
set tObj.WritesPerSec=writes/elapseTime
set tObj.ProcTime=elapseTime
set tObj.Processes=pNumProcesses
set tObj.ReadPct=0
$$$TOE(tSC,tObj.%Save())
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
quit tSC
]]></Implementation>
</Method>
<Query name="ExportSummary">
<Description>
SQL Query returns summary </Description>
<Type>%SQLQuery</Type>
<SqlQuery> SELECT RunDate,RunTime,Database,Namespace,
{fn ROUND(SUM(Reads),0)} As Reads,
{fn ROUND(SUM(Writes),0)} As Writes,
{fn ROUND(SUM(ReadsPerSec),0)} As "ReadsPS",
{fn ROUND(SUM(WritesPerSec),0)} As "WritesPS",
{fn ROUND(STDDEV_POP(Reads),3)} As "StdDevR",
{fn ROUND(STDDEV_POP(Writes)/AVG(Writes),3)} As "StdDevW",
Processes,ReadPct
FROM PerfTools.RanWrite
GROUP BY Batch</SqlQuery>
</Query>
<Method name="Export">
<Description>
Export all test history to comma delimited text file</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
#dim tSC as %Status = $$$OK
try {
//Check if directory exists
if ##class(%Library.File).DirectoryExists(pDirectory) {
set pathFilename=..GetPathFileName(pDirectory)
if pathFilename'="" {
write !,"Exporting summary of all random write statistics to "_pathFilename
//Open file
set file = ##class(%File).%New(pathFilename)
$$$TOE(tSC,file.Open("WNS"))
//Execute SQL query
set rs=##class(%ResultSet).%New("PerfTools.RanWrite:ExportSummary")
$$$TOE(tSC,rs.Execute())
//Write the headers
set colCount=rs.GetColumnCount()
for col=1:1:colCount {
do file.Write(rs.GetColumnName(col)_..#DELIM)
set type(col)=rs.GetColumnType(col)
}
do file.WriteLine()
//Loop through all rows and write out to comma delimited txt file.
while rs.Next() {
for col=1:1:colCount {
//Get field type
set type=type(col)
set data=rs.GetData(col)
if type=2 { //DATE // region agnostic YYYY-MM-DD format
do file.Write($zdate(data,3)_..#DELIM)
} else {
if type=8 {//TIME// 24 hours HH:MM:SS format
do file.Write($ztime(data,1)_..#DELIM)
} else {
do file.Write(data_..#DELIM)
}
}
}
do file.WriteLine()
}
//Close file
do file.Close()
write !,"Done."
}
} else {
set tSC=$$$ERROR($$$DirectoryNameInvalid,"Directory="_pDirectory)
do $system.OBJ.DisplayError(tSC)
}
} catch errObj {
set tSC = errObj.AsStatus()
do errObj.Log()
do $system.OBJ.DisplayError(tSC)
}
quit tSC
]]></Implementation>
</Method>
<Method name="GetPathFileName">
<Description>
Get full directory filename for export summary txt file.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pDirectory:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
//Normalize directory
set directory=##class(%Library.File).NormalizeDirectory(pDirectory)
//Get filename
set h=$horolog
//Get date in format yyyymmdd
set date=$zdatetime(+h,8)
//Get time in format hhdd
set time=$replace($ztime($piece(h,",",2),2),":","")
set filename=..#EXPORTFILENAME_date_"-"_time_..#FILEEXTENSION
set pathFilename=##class(%File).NormalizeFilename(filename,directory)
quit pathFilename
]]></Implementation>
</Method>
<Method name="GetTotalWritesPerSec">
<Description>
Return total Writes/sec for specified batch run</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>pBatch:%Integer</FormalSpec>
<ReturnType>%Double</ReturnType>
<Implementation><![CDATA[
#dim total as %Integer = 0
//Get total RPS
&sql(SELECT SUM(WritesPerSec)
INTO :total
FROM PerfTools.RanWrite
WHERE Batch=:pBatch)
quit total
]]></Implementation>
</Method>
<Method name="CountJobs">
<Description>