文章
· 九月 2 阅读大约需 2 分钟

如何定位临时global在IRISTEMP数据库中占用的空间

当进程中的数据不需要持久化保存,但又需要用到global的高性能特性时,我们常常将数据保存在临时global中,也就是保存在IRISTEMP/CACHETEMP数据库中。

系统使用 IRISTEMP/CACHETEMP 数据库保存临时的数据,用户也可以进行同样的操作。

关于临时global以及IRISTEMP数据库的更多内容,可以参见文档 Temporary Globals and the IRISTEMP Database

以下情况global作为临时使用:

  1. 系统临时global (^IRIS.Temp*, ^%cspSession, ^CacheTemp*, ^Mtemp*, 等)
  2. 用户定义的 globals 映射至 IRISTEMP/CACHETEMP 
  3. 处理私有globals (^||name, ^|"^"|name, ^["^"]name,^["^",""]name,等)
  4. GLOBAL TEMPORARY 表

1和2的大小可以通过使用 ^%GSIZE 获取

USER>do ^%GSIZE
Directory name: c:\intersystems\iris\mgr\user\ => c:\intersystems\iris\mgr\iristemp\
                            // 指明iristemp 数据库的位置
All Globals? No => yes       // Yes 为显示所有globals: 34 项被选中
34 available globals
Show details?? No => No   //  No 为不显示更多信息 
Device:
Right margin: 80 =>
:

3和4  进程私有global 可以通过使用 ^GETPPGINFO 查看。

更多关于 ^GETPPGINFO 的信息请查阅文档 这里

下面的例子列出了当前进程下所有的私有globals:

 set ^||flintstones(1)="Fred"
 set ^||flintstones(2)="Wilma"
 znspace "%SYS"
 do ^GETPPGINFO("*")

另一个方法用于输出单个进程使用较大数量的私有global:

 set ns=$namespace
 znspace "%SYS"
 // Only processes with more PPG blocks than the total number of processes are included
 set st=##class(%SQL.Statement).%New()
 set status=st.%PrepareClassQuery("%SYS.ProcessQuery","AllFields")
 set rs=st.%Execute()
 while rs.%Next() {
    set pid=rs.%Get("Pid") // Process ID
    set cnt=rs.%Get("PrivateGlobalBlockCount") // Number of PPG blocks
    // When the number of PPG blocks per process is 0 or more, the contents are output (the following example shows 20 or more blocks).
    if cnt > 20 {
       set rs2=##class(%ResultSet).%New("%SYS.ProcessQuery:PPG")
       // "N" Do not return subscripts of a PPG, just return the root name
       // "B" Return the number of blocks used by the PPG (needs the "N" option)
       do rs2.Execute("*",pid,"NB")
       for {
          quit:'rs2.Next()
          write cnt_" PID:"_pid_", PPG name "_rs2.GetData(1)_" is using "_rs2.GetData(3)_" disc blocks",!
       }
    }
 }
 
 znspace ns
讨论 (0)1
登录或注册以继续