WLB打开时,客户端(比如java程序的JCC driver,CLI程序的Db2 client)在每个transaction的边界,会根据特定算法找到最合适的member(即best member)把下一个transaction提交给它执行。
下面是java应用的一个例子,展示的是JCC trace:
[jcc][Time:2017-12-05-17:23:54.624][PreparedStatement@53d0ba2f]execute () called
...# before execute, find the best member to execute
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:310] skipped(not in the ratio) - currMember:0 currBestMember: 1 currMemberPriority: 24 currMemberRatio: 0.114832535 total transports in use: 1
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:320] selected(first time) currMember:1 currBestMember: 1 currMemberPriority: 85 currMemberRatio: 0.40669855 memberTransportsInUse_: 0 total connection: 1
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:340]{SWLBG@758447d9: m01.ibm.com/9.129.13.189 50001 sample 4 4 1 209
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:342] member:0 {SWLBN@6693b092: m01.ibm.com/9.129.13.189 50001 24 0.114832535 false 10 4 1 603 1 true
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:342] member:1 {SWLBN@2629cd1: m02.ibm.com/9.129.13.190 50001 85 0.40669855 false 10 4 4 23575 0 true
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:342] member:2 {SWLBN@18255e90: m03.ibm.com/9.129.13.191 50001 100 0.4784689 false 10 4 4 16817 0 true
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:342] member:3 {SWLBN@3d634c52: m00.ibm.com/9.129.13.188 50001 0 0.0 false 0 4 0 0 0 true
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:345] bestMember: 1 {SWLBN@2629cd1: m02.ibm.com/9.129.13.190 50001 85 0.40669855 false 10 4 4 23575 0 true
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:350] incrTranCount - openPosiSumHandlerThread bestmemberIndex: 1 {SWLBN@2629cd1: m02.ibm.com/9.129.13.190 50001 85 0.40669855 false 10 4 4 23576 1 true
[jcc]findBestSysplexMember [time:2017-12-05-17:23:54.624][tracepoint:230]findBestSysplexMember found member: {SWLBN@2629cd1: m02.ibm.com/9.129.13.190 50001 85 0.40669855 false 10 4 4 23576 1 true, bestMemberIndex= 1
...# find the best member, send itthe job to execute
[jcc][t4] [time:2017-12-05-17:23:54.624][tracepoint:635]got Transport: {T4GTPK@77978dad: 9.129.13.190 50001 db2sdin1 3 sample 4 -1130827284 108 false true isOrphan false DB2SimpleDataSource@3aaa1269:2,2147483647 a@440ae0f1 true com.ibm.db2.jcc.t4.ac@7ed69631[SET
...
[jcc][t4][time:2017-12-05-17:23:54.624][tracepoint:660][findTransportObject exited. Comparing special register size. On connection 1 on transport 1]
...
[jcc][Time:2017-12-05-17:23:55.208][PreparedStatement@53d0ba2f]execute () returned true
下面是具体的规则(英文的,在这里我就不翻译了):
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Member Priority = Comes from server (in DRDA code point SRVPRTY) as part of server list
Member Ratio (currMemberRatio) = Member Priority Sum of group member's Priority
Group Ratio = Sum of group member's ratio
Group transport count = Sum of group member's transport count
To select the best member, loop thru all the members. Starts with selecting first member:
If member does not have any transport in use, Then select it as best member and exit from the loop.
If selected member has more than 0 transport in use
Then check the below condition for the selected member:
result = transports in use by current member Group transport count <= Member Ratio Group Ratio
If result is true, Then select the current member as best and exit from the loop.
If result is false, Then continue the loop with selecting next member
You have to note that:
- Looking at the statistics I see that statements are distributed across all 3 members. Yeah some statements are run more on member 2, while some run more on member 1 and 3 as well.
- When we talk about load balancing, it should not be assumed that all members will have equal distribution of sql statements.
- Each statement will take different server CPU and Page resources.
- JCC keeps the server list cache for 30 seconds that contains the server priority info.
- JCC does not evaluate the sql statements, it distribute the transactions based on above logic and the priorities available in the server list at that point of time.
<<<<<<<<<<<<<<<<<<<<<<<<<<<




