load balancing active/active SAN’s

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 On

Disk 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 On

Disk 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 On

Disk 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 preferred

Disk 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 On

Disk 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 On

In 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.




You can leave a response, or trackback from your own site.

19 Responses to “load balancing active/active SAN’s”

  1. Load Balancing active/active SAN’s…

    Via Yellow-Bricks…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…

  2. What about using rr policy directly ?

  3. Well it’s definitely worth looking into, but it’s still experimental so I would not use it in a production site.

  4. 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

  5. It will chose another path automatically. this is fixes as in “preferred path”.

  6. 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

  7. 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

  8. Download the script. Upload it with winscp to your esx host. than run it with ./lbpath.sh

  9. [...] reading some older posts on Duncan Epping’s blog at Yellow-Bricks.com I found this posting for a console script which assigns the prefered LUN across 4 paths. The powershell script I posted [...]

  10. 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.

  11. bishop says:

    Ugh. The previous looked much better before the webform bobbitted the spacing.

  12. 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?

  13. [...] installations with lots of LUNs and an active/active SAN may find this script published by Duncan very helpful. The problem that this script addressed underscores the need for robust multipathing [...]

  14. pichita says:

    >Peter
    mmm… dos2unix ?

  15. 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?

  16. 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

  17. [...] pm After watching this video that was posted by the VI Toolkit team, I immediately thought of this script that was posted quite a while back on Yellow Bricks. I decided to try to recreate this script in [...]

  18. [...] load balancing active/active SAN’s » Yellow Bricks [...]

Leave a Reply

Subscribe to RSS Feed Follow me on Twitter!