Db2: db2pd apinfo 输出中为何会有两个Activity? Last reference time和Entry time为何不同?

在某次抓取的数据中,我们发现db2pd -apinfo的输出中有几个难以解释的现象:

1. List of current activities中为何不止一个activity ?
2. Last reference time和"Entry time"、"Local start time"都不一样,这是为什么?
3. 为什么应用状态显示的是UOW-Waiting,但却有活动的activities?

样例输出如下:

db2inst1@node01:~> db2pd -d sample -apinfo 53

Database Member 0 -- Database SAMPLE -- Active -- Up 0 days 00:02:30 -- Date 2020-05-06-07.48.21.534014

snapapp Time:   05/06/2020 07:48:21

Application :
  Address :                0x0000000203500080 
  AppHandl [nod-index] :   53       [000-00053]
  TranHdl :                14        
  Application PID :        0         
  Application Node Name :  192.168.75.133                          
  IP Address:              127.0.0.1                               
  Connection Start Time :  (1588765615)Wed May  6 07:46:55 2020
  Client User ID :         n/a     
  System Auth ID :         DB2INST1
  Coordinator EDU ID :     116       
  Coordinator Member :     0         
  Registered Agents :      1         
  Active Agents :          1         
  Locks timeout value :    NotSet
  Locks Escalation :       No
  Workload ID :            1         
  Workload Occurrence ID : 2         
  Trusted Context :        n/a
  Connection Trust Type :  non trusted
  Role Inherited :         n/a     
  Application Status :     UOW-Waiting         <---应用状态为 UOW-Waiting     
  Application Name :       db2jcc_application  
  Application ID :         127.0.0.1.51943.200506114655                                    
  ClientUserID :           n/a
  ClientWrkstnName :       192.168.75.133
  ClientApplName :         n/a
  ClientAccntng :          n/a
  CollectActData:          N  
  CollectActPartition:     C  
  SectionActuals:          N  
  UOW start time :         05/06/2020 07:46:55.922984
  UOW stop time :          

  Last executed statements :
    Package cache ID :                            0x0000011E00000001
    Anchor ID :                                   286
    Statement UID :                               1
    SQL Type :                                    Dynamic
    Statement Type :                              DML, Select (blockable)
    Statement :                                   select * from t2

  List of current activities :
    Activity ID :                                 2   <---第1个activity
    UOW-ID :                                      1
    Package schema :                              NULLID  
    Package name :                                SYSSH200
    Package Version :                             
    Consistency Token :                           SYSLVL01
    Section number :                              2
    Statement number :                            1
    Isolation :                                   CS
    Effective degree :                            0
    Actual degree    :                            1
    Sourece ID :                                  0
    Cursor ID :                                   0
    Nesting level :                               0
    Invocation ID :                               0
    Package cache ID :                            0x0000011E00000001
    Anchor ID :                                   286
    Statement UID :                               1
    SQL Type :                                    Dynamic
    Statement Type :                              DML, Select (blockable)
    Statement :                                   select * from t2
    Entry time :                                  05/06/2020 07:46:55.945310
    Local start time :                            05/06/2020 07:46:55.945313
    Last reference time :                         05/06/2020 07:48:16.046010  <---这个时间什么情况下和 Local start time 不一样?

    Activity ID :                                 1   <---第2个activity,这是怎么回事?
    UOW-ID :                                      1
    Package schema :                              NULLID  
    Package name :                                SYSSH200
    Package Version :                             
    Consistency Token :                           SYSLVL01
    Section number :                              1
    Statement number :                            1
    Isolation :                                   CS
    Effective degree :                            0
    Actual degree    :                            1
    Sourece ID :                                  0
    Cursor ID :                                   0
    Nesting level :                               0
    Invocation ID :                               0
    Package cache ID :                            0x000003B000000001
    Anchor ID :                                   944
    Statement UID :                               1
    SQL Type :                                    Dynamic
    Statement Type :                              DML, Select (blockable)
    Statement :                                   select * from t1
    Entry time :                                  05/06/2020 07:46:55.927095
    Local start time :                            05/06/2020 07:46:55.927098
    Last reference time :                         05/06/2020 07:48:16.045405

于是开了case咨询了IBM, 根据IBM给出的示例以及解释,设计了下面的java程序,当运行程序之后,db2pd -apinfo的输出就是上面的结果,关键点有两个:

1. 打开两个游标,就会看到两个activity

2. 设置了fetchSize为10,每次取完一条记录后sleep 1秒钟,这样子每10秒就会fetch一次,观察db2pd -apinfo的输出就会发现中Last  reference time 每10秒变一次,但"Entry time"、"Local start time"都不变

#File name FirstClass.java
import java.sql.*;  
  
public class FirstClass {  
  
    public static void main(String args[]) {  
  
        try {  
            Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();  
              
            String url = "jdbc:db2://localhost:60000/sample";  
            String user = "db2inst1";  
            String password = "db2inst1";  
              
            System.out.println("try");  
            Connection conn = DriverManager.getConnection(url, user, password);  
            System.out.println("success");  
              
            PreparedStatement ps1 = conn.prepareStatement("select * from t1");
            PreparedStatement ps2 = conn.prepareStatement("select * from t2");
            ps1.setFetchSize(10);
            ps2.setFetchSize(10);
 
            ResultSet rs1 = ps1.executeQuery();  
            ResultSet rs2 = ps2.executeQuery();
            while (rs1.next() && rs2.next())  
            {   
            	int id_1 = rs1.getInt("ID");
            	int id_2 = rs2.getInt("ID");
            	System.out.println("ID_1: " + id_1 );
            	System.out.println("ID_2: " + id_2 );
            	System.out.println("-------------------");
            	Thread.sleep(1000);
            }
              
            conn.close();  
             
        } catch (Exception sqle) {  
            System.out.println(sqle);  
        }  
          
        return;  
    }  
}  

# /opt/ibm/db2/V10.5/java/jdk64/bin/javac FirstClass.java
# /opt/ibm/db2/V10.5/java/jdk64/bin/java FirstClass

Reference time is updated when an activity is "referenced", meaning a new request arrives. So for a cursor this would the the arrival time of open or last fetch request. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值