IBM i Global

IBM i Global

Connect, learn, share, and engage with IBM Power.

 View Only
Expand all | Collapse all

Memory consumption via SQL

  • 1.  Memory consumption via SQL

    Posted Wed October 23, 2024 04:02 PM

    Hello. I am trying to setup an exporter for Prometheus to monitor system performance. I'm using an existing java-based exporter from github that uses SQL statements to get the metric values. Unfortunately it doesn't come with a metric for memory consumption. The query it's using for memory statistics is:

    "SELECT POOL_NAME,CURRENT_SIZE,DEFINED_SIZE,MAXIMUM_ACTIVE_THREADS,CURRENT_THREADS,RESERVED_SIZE FROM TABLE(QSYS2.MEMORY_POOL(RESET_STATISTICS=>'YES')) X"

    This gives me some data, but not what I need to determine memory consumption.

    I looked through the discussions in this group, and did quite a lot of googling, and the only method I've seen to get an actual value for memory consumption is via the Navigator (Old Interface > Performance > Investigate Data) to see usage per pool. I looked at the query used for these graphs, and it appears to be querying a temporary performance data table (QTEMP.QPFRDATAQAPMPOOLBQ295000002). I couldn't figure out how to use this for my query, though.

    If anyone knows of a query that will give me the current consumption of a single pool, or the entire memory, I would greatly appreciate it.



    ------------------------------
    Jacob Curtis
    ------------------------------


  • 2.  RE: Memory consumption via SQL

    Posted Thu October 24, 2024 03:02 AM

    Dear Jacob

    There is little use in IBM i for knowing a subsystem's memory consumption because each memory pool can be automatically adjusted based on its page faulting rate - the high-faulting pool can steal memory from the low-faulting pool.  This is done every minute (adjustable) by setting IBM i system value QPFRADJ to a value of 2.   Many customers have separate memory pools for interactive and batch workloads. During the day time, there is more interactive workload than batch and interactive pool needs more memory.  But it's the reverse for the night time and this is the case when memory adjuster is useful.   But many client-server type of application in IBM i has all its subsystems allocated to one common memory pool (mostly pool 2) and they run all kind of jobs in this same memory pool and there is no much need to adjust the pool size.

    Do you have QPFRADJ set to zero?   If you have all subsystems that have workload all day long, then you do not need memory adjuster.  But you need to observe memory faulting characterictic of these memory pools to be able to allocate proper size to each pool that is commensurate to its respective peak faulting rate and review it every few months.

    When using memory adjuster, you should also set lower and upper limit to each memory pool's size with WRKSHRPOOL command as described here:  Admin Alert: Tuning i5/OS Storage Pools for Performance at https://www.itjungle.com/2008/12/03/fhg120308-story03/     The *MACHINE pool (pool number 1) should be set a fixed size of 2-2.5 times its "reserved size" as seen from WRKSYSSTS command around the peak workload period.

    Other OSes need memory consumption information because they do not have multiple memory pools and memory faulting has more performance overhead (especially in the time when HDD is used) than IBM i.   For IBM i, if your disk HW provides consistently decent response time, say 5 msec. or less at all time, faulting is not that costly. (Use SSD and you can sleep more soundly.)  IBM i also uses single-level storage in which all jobs see only one virtual memory space as opposed to other OSes in which each job sees 2 memory spaces - virtual one and the physical RAM memory space and managing RAM space is beneficial but you need not do this in IBM i. 

    In summary, it's not that serious in IBM i to know subsystem's memory consumption in a regular manner.  Knowing memory faulting rate and disk response time is more useful in IBM i.



    ------------------------------
    Satid S
    ------------------------------



  • 3.  RE: Memory consumption via SQL

    Posted Thu October 24, 2024 06:05 AM
    Edited by Rudi Van Helvoirt Thu October 24, 2024 06:05 AM

    Hello Jacob,

    Let the Navigator for i (Nav4i) give a helping hand ;-)

    Logon to Nav4i and go to => Performance => Investigate Date => Memory Usage by Pool.

    When doing this a graph will show and in the top right corner of that graph you will see an SQL button.

    • Please press that button and a window will appear showing you the  SQL statement used for the first graph.
    • Copy and paste that SQL statement into Run SQL Script of IBM i Access Client Solutions.
    • Add the line above that SQL statement shown below:
      create or replace alias qrplobj.qapmpoolb for QPFRDATA.QAPMPOOLB(*LAST);
    • now replace the string "QTEMP.QPFRDATAQAPMPOOLBQ288000025" by QRPLOBJ.QAPMPOOLB ( please be aware that you have a different number in the "Q288000025")
    • Based on you Collection Services Interval you could decide to run this command on a refresh rate based on that. The create or replace alias SQL statement needs only to be run when after Collection Services has cycled. For this information use Nav4i => Performance => Collection Services Configuration
    • Since you are only interested in the last collection of data please add the following in the SQL statement just after the table name:
      where datetime >= current timestamp - 5 minutes (again the 5 minutes used here is base on the collection interval used in the Collection Services Configuration.

    I can only hope this helps and if it does not, I enjoyed putting it together and learned a lot doing so. So thanks for asking.

    Although I agree with what Satid wrote I nonetheless decided to try to help you.

    We use the information provided in the graph to check if there is memory available not being used. As I am Dutch I do like things which are for free to use ;-)

    Greetings,



    ------------------------------
    Rudi Van Helvoirt
    ------------------------------



  • 4.  RE: Memory consumption via SQL

    Posted Tue October 29, 2024 04:41 PM

    Hi Rudi,

    Thanks for your response. I have a question about your solution, if you wouldn't mind elaborating.

    I tried creating the alias for QAPMPOOLB, but the query failed. I ran: 

    `create alias qrplobj.qapmpoolb for QPFRDATA.QAPMPOOLB(*LAST);`

    and got the error

    `Token * was not valid. Valid tokens: <IDENTIFIER>. SQLSTATE=42601 SQLCODE=-104`.

    Did I use the wrong syntax, or am I missing something?



    ------------------------------
    Jacob Curtis
    ------------------------------



  • 5.  RE: Memory consumption via SQL

    Posted Tue October 29, 2024 11:00 PM
    Edited by Satid S Tue October 29, 2024 11:00 PM

    Dear Jacob

    >>>> create alias qrplobj.qapmpoolb for QPFRDATA.QAPMPOOLB(*LAST) <<<<

    *LAST is valid only for IBM i CL command, not SQL.  You need to explicitly specify the last member name of QAPMPOOLB. Use DSPFD command against QAPMPOOLB to see its last member's name.



    ------------------------------
    Satid S
    ------------------------------



  • 6.  RE: Memory consumption via SQL

    Posted Wed October 30, 2024 03:30 AM

    Hello Jacob/Satid,

    The ability to use *LAST is part of IBM i 7.5 TR4 & IBM i 7.4 TR 10 and is documented here.
    So I assume your error is because of the fact that you are running that SQL statement on a LPAR not running one of these versions having that TR level installed.
    In order to be able to use *LAST for  IBM i 7,4 the Db2 group PTF level 28 is needed, for IBM i 7.5 it is Db2 group PTF level 7.

    As always staying a current up to date level of IBM i makes your life as a system administrator easier. 

    Greetings, 



    ------------------------------
    Rudi Van Helvoirt
    ------------------------------



  • 7.  RE: Memory consumption via SQL

    Posted Wed October 30, 2024 08:50 AM

    Jacob

    Since Rudi already mentioned that you need to be at TR 10 (7.4) to get the *LAST support on the create alias statement....you might want to have a front end pgm that creates the alias for you in a CL program. I do something similar to harvest some perf data as well - example of retrieving the last member and then creating the alias on CL:

    RTVMBRD    FILE(QPFRDATA/QAPMSYSAFN) MBR(*LAST) +     
                 RTNMBR(&MBRNAME)                         

    QSYS/RUNSQL SQL('CREATE OR REPLACE ALIAS +          
                 QTEMP.TODAY         FOR +              
                 QPFRDATA.QAPMSYSAFN (' *CAT &MBRNAME + 
                 *TCAT ')') COMMIT(*NONE) NAMING(*SQL)  

    hope this helps - Rich

    P.S - on the memory utilization front..I do find it useful to see what the actual consumption is....i.e - do I have memory sitting idle / not allocated etc. I use iDoctor over the CS data though to get me that info and have found it very useful in lowering the amount of faults I have as well as identifying where I have "too much" memory in pools that simply don't need it. 



    ------------------------------
    Rich Malloy
    ------------------------------



  • 8.  RE: Memory consumption via SQL

    Posted Wed October 30, 2024 11:45 AM

    Hello Rich,

    For looking at the memory usage iDoctor is no longer needed, IBM i comes out of the box with a graph with which you can view the Memory Usage by Pool:

    Graph available in Navigator for i
    Greetings,


    ------------------------------
    Rudi Van Helvoirt
    ------------------------------



  • 9.  RE: Memory consumption via SQL

    Posted Wed October 30, 2024 11:53 AM

    Hi Rudi

    Its more of my preference, I prefer the idoctor tools - especially since I spend a lot of time using it for Job Watcher anyway. Thanks



    ------------------------------
    Rich Malloy
    ------------------------------



  • 10.  RE: Memory consumption via SQL

    Posted Wed October 30, 2024 12:12 PM

    Hello Rich,

    Please do not understand me wrong, iDoctor is a brilliant tool. It is a pity it is Windows only.
    Regarding Job Watcher iDoctor outperforms Navigator for i, but for the average IBM i System Administrator the Navigator for i graphs will do fine. 

    It is a matter of taste for sure, but the Graphs in Navigator for i look much better ;-)

    As I am Dutch I do like things which come for free, iDoctor does require your wallet.

    As always feel 100 % free to disagree with me. According to my kids I am always wrong. 

    Greetings, 



    ------------------------------
    Rudi Van Helvoirt
    ------------------------------



  • 11.  RE: Memory consumption via SQL

    Posted Wed October 30, 2024 12:18 PM

    LOL - and see, I like the graphics better in iDoctor...haha

    at some point, your kids will say something that gives you 'recognition' for NOT always being wrong! :-) 

    It might take a couple of decades..but it will happen....



    ------------------------------
    Rich Malloy
    ------------------------------



  • 12.  RE: Memory consumption via SQL

    Posted Thu October 31, 2024 06:41 AM
    Edited by Satid S Thu October 31, 2024 06:45 AM

    Dear Rich

    >>>> on the memory utilization front..I do find it useful to see what the actual consumption is....i.e - do I have memory sitting idle / not allocated etc. I use iDoctor over the CS data though to get me that info and have found it very useful in lowering the amount of faults I have as well as identifying where I have "too much" memory in pools that simply don't need it.  <<<<

    I'm wondering if you are aware that you can achieve your stated goals more conveniently by setting the system value QPFRADJ=2 as it would move memory from low-faulting pool to the high-faulting one for you automatically every minute - definitely better than looking at iDoctor data every minute manually!   And you have an option to set the max and min memory pool size (with WRKSHRPOOL) which is important for *MACHINE pool which should be fixed at around 2-2.5 times its Reserves Size as seen from WRKSYSSTS.    



    ------------------------------
    Satid S
    ------------------------------



  • 13.  RE: Memory consumption via SQL

    Posted Thu October 31, 2024 08:30 AM

    Hi Satid, 

    Yes, we PFRADJ is turned on. We are very aggressive with our Mins and Max's for our pools and while we technically can let the system move the memory, our workloads and users are very sensitive to latency. We don't look at idoctor every minute..lol......after we setup the mins and max pool sizes, we then look at the CS data via iDOCTOR to see if we either guessed to high on the min or not high enough on the max.....and then make adjustments. knowing not only how much memory is unallocated but also knowing WHEN there is high demand or even 'low demand' has allowed us more flexibility in freeing memory up from one set of pools and making them more available to another set. 



    ------------------------------
    Rich Malloy
    ------------------------------