Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   Improving Individual Query Performance > SQL Statement Cache >

Monitoring Memory Usage for Each Session

You can use arguments of the onstat -g option to obtain memory information for each session.

To identify SQL statements using large amount of memory
  1. Use the onstat -u option to view all user threads.
  2. Use the onstat -g ses option to view memory of all sessions and see which session has the highest memory usage.
  3. Use the onstat -g ses session-id option to view more details on the session with the highest memory usage.
  4. Use the onstat -g stm session-id option to view the memory used by the SQL statements.

onstat -g ses

The onstat -g ses displays memory usage by session id. When the session shares the memory structures in the SSC, the value in the used memory column should be lower than when the cache is turned off. For example, Figure 74 shows sample onstat -g ses output when the SQL statement cache is not enabled, and Figure 75 shows output after it is enabled and the queries in Session 4 are run again. Figure 74 shows that Session 4 has 45656 bytes of used memory. Figure 75 shows that Session 4 has less used bytes (36920) when the SSC is enabled.

Figure 74. onstat -g ses Output when the SQL Statement Cache Is Not Enabled
session                                      #RSAM    total      used
id       user     tty      pid      hostname threads  memory     memory
12       informix -        0        -        0        12288      7632
4        informix 11       5158     smoke    1        53248      45656
3        informix -        0        -        0        12288      8872
2        informix -        0        -        0        12288      7632

Figure 75. onstat -g ses Output when the SQL Statement Cache Is Enabled
session                                      #RSAM    total      used
id       user     tty      pid      hostname threads  memory     memory
17       informix -        0        -        0        12288      7632
 16        informix 12       5258     smoke    1         40960        38784 
 4         informix 11       5158     smoke    1         53248        36920 
3        informix -        0        -        0        12288      8872
2        informix -        0        -        0        12288      7632

Figure 75 also shows the memory allocated and used for Session 16, which executes the same SQL statements as Session 4. Session 16 allocates less total memory (40960) and uses less memory (38784) than Session 4 (Figure 74 shows 53248 and 45656, respectively) because it uses the existing memory structures in the SQL statement cache.

onstat -g ses session-id

The onstat -g ses session-id option displays detailed information for a session. The following onstat -g ses session-id output columns display memory usage:

Figure 76 shows that Session 16 has currently allocated 69632 bytes, of which 11600 bytes are allocated from the sscpool.

Figure 76. onstat -g ses session-id Output
onstat -g ses 14


session                                      #RSAM    total      used
id       user     tty      pid      hostname threads  memory     memory
14       virginia 7        28734    lyceum   1        69632      67384     

tid      name     rstcb    flags    curstk   status
38       sqlexec  a3974d8  Y--P---  1656     cond wait(netnorm)

Memory pools    count 1
name         class addr      totalsize   freesize  #allocfrag #freefrag
14           V     a974020   69632       2248      156        2 

...
Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
14    SELECT         vjp_stores         CR  Not Wait   0    0    9.03

Current statement name : slctcur

Current SQL statement :
  SELECT C.customer_num, O.order_num FROM customer C, orders O, items I
    WHERE C.customer_num = O.customer_num AND O.order_num = I.order_num

Last parsed SQL statement :
  SELECT C.customer_num, O.order_num FROM customer C, orders O, items I
    WHERE C.customer_num = O.customer_num AND O.order_num = I.order_num

 11600 byte(s) of memory is allocated from the sscpool 

onstat -g sql session-id

The onstat -g sql session-id option displays information about the SQL statements executed by the session. Figure 77 shows that onstat -g sql session-id displays the same information as the bottom portion of the onstat -g ses session-id in Figure 76, which includes the number of bytes allocated from the sscpool.

Figure 77. onstat -g sql session-id Output
onstat -g sql 14


Sess  SQL            Current            Iso Lock       SQL  ISAM F.E.
Id    Stmt type      Database           Lvl Mode       ERR  ERR  Vers
14    SELECT         vjp_stores         CR  Not Wait   0    0    9.03

Current statement name : slctcur

Current SQL statement :
  SELECT C.customer_num, O.order_num FROM customer C, orders O, items I
    WHERE C.customer_num = O.customer_num AND O.order_num = I.order_num

Last parsed SQL statement :
  SELECT C.customer_num, O.order_num FROM customer C, orders O, items I
    WHERE C.customer_num = O.customer_num AND O.order_num = I.order_num

 11600 byte(s) of memory is allocated from the sscpool 

onstat -g stm session-id

The onstat -g stm session-id option displays information about the memory each SQL statement uses in a session. Figure 78 displays the output of onstat -g stm session-id for the same session (14) as in onstat -g ses session-id in Figure 76 and onstat -g sql session-id in Figure 77. When the SQL statement cache is on, the database server creates the heaps in the sscpool. Therefore, the heapsz output field in Figure 78 shows that this SQL statement uses 10056 bytes, which is contained within the 11600 bytes in the sscpool that the onstat -g sql 14 shows.

Figure 78. onstat -g stm session-id Output
onstat -g stm 14


session   14 ---------------------------------------------------------------
 sdblock   heapsz   statement ('*' = Open cursor)
 aa11018    10056  *SELECT C.customer_num, O.order_num
FROM customer C, orders O, items I
WHERE C.customer_num = O.customer_num
AND O.order_num = I.order_num
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]