%GSIZE vs %SYS.GlobalQuery for Estimating Size of Globals

Hey everyone, 

I stumbled across a comment in this post that mentioned that the %SYS.GlobalQuery is a potentially faster alternative to %GSIZE. I tested it out and while I like the %SYS.GlobalQuery I noticed that it has some size discrepancies against a %GSIZE with details.  Can anyone tell me which is more accurate for estimating the size of globals?

 

Here is an example of one of the differences I saw. From this it looks like the size is estimated to about 70gb from %GSIZE and about 67gb from %SYS.GlobalQuery.

%GSIZE Output:

Ens.MessageBodyD
                   8830691   70,452,447,461     98 %   8,194,352
%SYS.GlobalQuery Output:

                  Ens.MessageBodyD, 68990, 67189

  • 0
  • 0
  • 59
  • 1
  • 1

Answers

There is also ClassMethod GetGlobalSize in the class %Library.GlobalEdit , where you can select a fast way to count or not, and you will get a different result.

 ClassMethod GetGlobalSize(Directory As %String, GlobalName As %String, ByRef Allocated As %Integer, ByRef Used As %Integer, fast As %Boolean = 0) as %Status

Get size of this global
'Allocated' - total size, in MB, of blocks allocated for the global.
'Used' - total used data, in MB, for the global.
'fast' - TRUE : faster return, it won't return the value of 'Used'.
FALSE - slower return,, it returns values for both 'Allocated' and 'Used'.

So, when fast, it just counts blocks and don't care how those blocks fill by data and multiply the number of blocks on Size of the block.

Used, counts only when you pass fast=0, and it calculates exact size, and to be more accurate reads all blocks, so it could be slower.

 

Both methods of calculation give the similar results in fast mode, while the %Library.GlobalEdit's one seems to be faster. The results of sizing of rather big global are:

< restart Caché >

USER>set t0=$zh
USER>set sc=##class(%Library.GlobalEdit).GetGlobalSize($zu(12,""),"zzz",.a,.u,1)
USER>zwrite sc,a,u write $zh-t0
sc=1
a=135819
22.542591

< restart Caché >

USER>set t0=$zh
USER>set as=$$AllocatedSize^%GSIZE("^zzz")/1024\1024
USER>zwrite as w $zh-t0
as=135818
28.29038

I withdrawing the comparison result as my testing environment was not stable (~ %30 "natural" fluctuations due to cloud hosting specific). Planning to repeat the test after getting more stable environment with such a large global(s).