Comments (5)
Been thinking about this one but have not found any way to make it substantially faster. I read that in environments using Unicode that adding 'export LC_ALL="C" ' at the top of the script can speed calls to standard Unix string searching utilities (e.g. grep). My locale is en_CA.UTF-8 (i.e. not Unicode) and that export made a small improvement. I'm open to ideas from others. Also could you quantify "too slow"?
from sg3_utils.
we found there is a O(n^2) in this func which comes from "while" and "findmultipath", and we use this shell like "scsi-rescan -f -u -m", so if a lun has m paths, loop times equals to m * 1K * 1K。
now we use a temporary file to record information of mpath in advance :
getallmultipathinfo()
{
local mp=
local uuid=
local dmtmp=
local maj_min=
local tmpfile=
for mp in $($DMSETUP ls --target=multipath | cut -f 1) ; do
[ "$mp" = "No" ] && break;
maj_min=$($DMSETUP status "$mp" | cut -d " " -f14)
if [ ! -L /dev/mapper/${mp} ]; then
echo "softlink /dev/mapper/${mp} not available."
continue
fi
local ret=$(readlink /dev/mapper/$mp 2>/dev/null)
if [[ $? -ne 0 || -z "$ret" ]]; then
echo "readlink /dev/mapper/$mp failed. check multipath status."
continue
fi
dmtmp=$(basename $ret)
uuid=$(cut -f2 -d- "/sys/block/$dmtmp/dm/uuid")
echo "$mp $maj_min $dmtmp $uuid" >> $TMPLUNINFOFILE
done
}
findmultipath(){
……
maj_min=$(cat "/sys/block/$dev/dev")
mp=$(cat $TMPLUNINFOFILE | grep -w "$maj_min" | cut -d " " -f1)
if [ -n "$mp" ]; then
if [ -n "$find_mismatch" ] ; then
uuid=$(cat $TMPLUNINFOFILE | grep -w "$maj_min" | cut -d " " -f4)
if [ "$find_mismatch" != "$uuid" ] ; then
addmpathtolist "$mp"
found_dup=1
fi
else
# Normal mode: Find the first multipath with the sdev
# and add it to the list
addmpathtolist "$mp"
return
fi
fi
……
}
findremapped(){
……
udevadm_settle 2>&1 /dev/null
echo "Done"
getallmultipathinfo
# See what changed and reload the respective multipath device if applicable
while read -r hctl sddev id_serial_old ; do
……
}
“Also could you quantify "too slow"?”:I will e-mail you a result of contrast later on
from sg3_utils.
Looks good. I think you need something like 'truncate -s 0 $TMPLUNINFOFILE' at the start of getallmultipathinfo() since rescan-scsi-bus.sh may be called more than once. Look forward to your timings report showing a significant improvement.
from sg3_utils.
We tested with “rescan-scsi-bus -f -u -m” on the original and optimized script. All SCSI devices have been mapped to dm device.
Here is the comparison of time spent before and after optimization:
Number of LUN | Number of Path | Before optimization | After optimization |
---|---|---|---|
128 | 16 | 213m21s | 2m35s |
256 | 16 | 967m54s | 5m27s |
We found the most time exhausted on these two code lines in original script:
findmultipath()
{
……
mp2=$($MULTIPATH -l "$mp" | egrep -o "dm-[0-9]+")
mp2=$(cut -f2 -d- "/sys/block/$mp2/dm/uuid")
……
}
They spent almost 5 seconds when there are 128LUNs * 16paths, and 10~15 seconds when 256LUNs * 16paths each execute. And the outer loop should loop 2k or 4k times.
After optimization,we do not need these two lines any more.
from sg3_utils.
I have placed this patch in svn revision 973 now mirrored. Perhaps you could check if that as been done accurately and that the impressive speed-up is still present.
from sg3_utils.
Related Issues (16)
- The sorting order of the output numeric part is out of order HOT 3
- shared library SONAME HOT 2
- rescan_scsi_bus.sh: Why it's pointless to do a target scan on FC ? HOT 3
- rescan-scsi-bus.sh: when there is a logical lun-0, testonline will spend 30s to retry-check it HOT 6
- Identify device output for SATA on big endian HOT 11
- Strange behavior of sg_inq -HH option HOT 2
- invalid VPD response; probably a STANDARD INQUIRY response HOT 2
- Regression in sgp_dd command HOT 4
- Input parameter handling for sg_wr_mode fails... HOT 3
- sg_logs: output for Device Statistics page (14h), serial numbers should be strings? HOT 5
- rescan-scsi-bus.sh: -r flag unmounts active root disk HOT 3
- Something weird happened in windows... please help me understand. HOT 3
- interaction between sg_start and systemd-udevd may spin-up disk immediately after spin-down HOT 4
- sg_ses: order of low_crit and low_warn thresholds is mixed for `--get` command
- mmap IO example mistake HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sg3_utils.