Ernst, a regular poster of the Dutch VMug, posted a script for load balancing paths to an active/active SAN. What it does is select the next path for a LUN, in other words if there are four paths LUN1 will be reached via Path1, LUN2 via Path2 etc.
The script, also available for download here:
#!/bin/bash
for PATHS in 2 4 6 8
do
STPATHS=${PATHS}
COUNTER=”1″for LUN in $(esxcfg-mpath -l | grep “has ${STPATHS} paths” | awk ‘{print $2}’)
do
esxcfg-mpath –lun=${LUN} –path=$(esxcfg-mpath -q –lun=${LUN} | grep FC | awk ‘{print $4}’ | awk ‘{print NR “S\t ” $0}’ | grep ${COUNTER}S | awk ‘{print $2}’) –preferred
COUNT=`expr ${COUNTER} + 1`
COUNTER=${COUNT}
if [[ ${COUNTER} -gt ${STPATHS} ]]
then
COUNTER=”1″
fi
done
done
This will result in the following outcome with “esxcfg-mpath -l”:
Disk vmhba2:1:4 /dev/sdh (512000MB) has 4 paths and policy of Fixed
FC 16:0.1 50060b0000646c8a<->50060e8004f2e812 vmhba2:1:4 On active preferred
FC 16:0.1 50060b0000646c8a<->50060e8004f2e873 vmhba2:2:4 On
FC 19:0.1 50060b0000646062<->50060e8004f2e802 vmhba4:1:4 On
FC 19:0.1 50060b0000646062<->50060e8004f2e863 vmhba4:2:4 OnDisk vmhba2:1:5 /dev/sdi (512000MB) has 4 paths and policy of Fixed
FC 16:0.1 50060b0000646c8a<->50060e8004f2e812 vmhba2:1:5 On
FC 16:0.1 50060b0000646c8a<->50060e8004f2e873 vmhba2:2:5 On active preferred
FC 19:0.1 50060b0000646062<->50060e8004f2e802 vmhba4:1:5 On
FC 19:0.1 50060b0000646062<->50060e8004f2e863 vmhba4:2:5 OnDisk vmhba2:1:6 /dev/sdj (307200MB) has 4 paths and policy of Fixed
FC 16:0.1 50060b0000646c8a<->50060e8004f2e812 vmhba2:1:6 On
FC 16:0.1 50060b0000646c8a<->50060e8004f2e873 vmhba2:2:6 On
FC 19:0.1 50060b0000646062<->50060e8004f2e802 vmhba4:1:6 On active preferred
FC 19:0.1 50060b0000646062<->50060e8004f2e863 vmhba4:2:6 OnDisk vmhba2:1:7 /dev/sdk (307200MB) has 4 paths and policy of Fixed
FC 16:0.1 50060b0000646c8a<->50060e8004f2e812 vmhba2:1:7 On
FC 16:0.1 50060b0000646c8a<->50060e8004f2e873 vmhba2:2:7 On
FC 19:0.1 50060b0000646062<->50060e8004f2e802 vmhba4:1:7 On
FC 19:0.1 50060b0000646062<->50060e8004f2e863 vmhba4:2:7 On active preferredDisk vmhba2:1:8 /dev/sdl (512000MB) has 4 paths and policy of Fixed
FC 16:0.1 50060b0000646c8a<->50060e8004f2e812 vmhba2:1:8 On active preferred
FC 16:0.1 50060b0000646c8a<->50060e8004f2e873 vmhba2:2:8 On
FC 19:0.1 50060b0000646062<->50060e8004f2e802 vmhba4:1:8 On
FC 19:0.1 50060b0000646062<->50060e8004f2e863 vmhba4:2:8 OnDisk vmhba2:1:9 /dev/sdm (512000MB) has 4 paths and policy of Fixed
FC 16:0.1 50060b0000646c8a<->50060e8004f2e812 vmhba2:1:9 On
FC 16:0.1 50060b0000646c8a<->50060e8004f2e873 vmhba2:2:9 On active preferred
FC 19:0.1 50060b0000646062<->50060e8004f2e802 vmhba4:1:9 On
FC 19:0.1 50060b0000646062<->50060e8004f2e863 vmhba4:2:9 OnIn other words, when you run this script each LUN will be addressed via a specific path and all HBA’s and SAN Disk Controllers will be used instead of the default first path / first controller policy. This will result in a better performance and distribution of load on the SAN Disk Controllers.
SUGLIANI Timo says
What about using rr policy directly ?
Duncan Epping says
Well it’s definitely worth looking into, but it’s still experimental so I would not use it in a production site.
vinod says
This is great script. I need help in fixing an issue in my envirionment and looking for similar kind of script but with little changes.
My storage is active/active EVA 81k. The LUN A at EVA is configured for Controller A Failover/Failback and lun B is configured for Controller B failover/failback
Requirement:
for lun A (vmhba1:0:1)we want to load balance it with 4 ports of controller A (8,9,a,b)
for lun B (vmhba1:0:2)we want to load balance it with 4 ports of controller B (c,d,e,f)
Could you please help to acheive the above requirement please.
Thanks! in advance..
Duncan says
Why not just use Round Robin?
Chris says
Hi,
what happens if I loose one path, will ESX than automatically switch to an other or is the setup via the script fix?
Regards,
Chris
Duncan Epping says
It will chose another path automatically. this is fixes as in “preferred path”.
Ernst (Himself) says
@Duncan: We have the script running in a production enviroment with +/-1400 VM’s and its working splendid
@Chris: If one patth fails ESX will automaticly failover to one of the other paths. We tested this extencively and it was working just fine even under heavy load
Lasse says
Would be nice for us. Have over 400 VM’s
I’m a new at scripting, anyone can get me a tip how to run this
Duncan Epping says
Download the script. Upload it with winscp to your esx host. than run it with ./lbpath.sh
bishop says
Toss a sleep into the loop there. Our EMC SAN doesn’t seem to be robust enough to handle all those path changes without wedging itself. Our customers were not pleased when we had to shut down an entire cluster, un-present a LUN, bring up the cluster without the VMs using that LUN, allow the SAN to run a verification and then re-present the LUN and bring up the VMs.
so:
then
COUNTER=”1″
+ sleep 1800
fi
done
done
Don’t be like me, kids. Keep your SAN people happy.
bishop says
Ugh. The previous looked much better before the webform bobbitted the spacing.
Peter says
Script is not working for me…
grep: 2: No such file or directory
grep: paths.: No such file or directory
awk: cmd. line:1: .{print
awk: cmd. line:1: ^ parse error
awk: cmd. line:2: (END OF FILE)
awk: cmd. line:2: parse error
grep: 4: No such file or directory
grep: paths.: No such file or directory
awk: cmd. line:1: .{print
awk: cmd. line:1: ^ parse error
awk: cmd. line:2: (END OF FILE)
awk: cmd. line:2: parse error
grep: 6: No such file or directory
grep: paths.: No such file or directory
awk: cmd. line:1: .{print
awk: cmd. line:1: ^ parse error
awk: cmd. line:2: (END OF FILE)
awk: cmd. line:2: parse error
grep: 8: No such file or directory
grep: paths.: No such file or directory
awk: cmd. line:1: .{print
awk: cmd. line:1: ^ parse error
awk: cmd. line:2: (END OF FILE)
awk: cmd. line:2: parse error
What did ido wrong?
pichita says
>Peter
mmm… dos2unix ?
Duncan Epping says
probably indeed
varya says
hi,i am a noob.
i have 256 LUNs with MRU policy. i want to change all of them to fixed; can i use the above script?
Duncan says
Yes you can, but is your SAN an active/active SAN or an Active/Passive SAN. If it’s an A/P SAN you must use MRU! Check the VMware compatability guide before you make the change!
You would just need to add the line for the set to fixed bit.
Duncan
rotary laser levels says
Thank you so much for your opinion on load balancing active/active SAN’s » Yellow Bricks , I totally agree with you. It is fantastic to see a fresh outlook on this and I look forward to more.
Kamil Azmer says
Hi.
I like to ask regarding the esx storage policy, If i’m was using RR policy and not active the ALUA what will be happen and it’s will work for load-balancing?
How it’s stable on vsphere 4.0 non update.
What is the best setting for single processor controller with 2 path? Should i set to RR or FIXED?.
Thank you