Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, my friends.
I made a little script with 'for' cycle.
On different linux servers that script rounds different number of times.
Is it real to identify how many times was asked command during script was running?
Script:
Code:
time for j in `sudo multipath -ll | grep 'MY_STORAGE_NAME' | awk '{print $1}'`;do echo $(echo $j; echo $(for i in `sudo multipath -ll|grep 'MY_STORAGE_NAME'|awk '{print $2}'|awk -F \( '{print$2}'|awk -F \) '{print $1}'`;do echo $(sudo multipath -a $i -ll |grep sd |awk '{print $3}';sudo multipath -a $i -ll | grep 'MY_STORAGE_NAME'|awk '{print $1}');done |awk '{for(k=1; k<=NF; k++) print $k,$NF}'|grep sd | awk '{if($2=="'"$j"'") print $0;}'|awk '{print $1}'));done
How many times command multipath was running if it is N disks from storage?
command 'time sudo multipath -ll' performed for 0.1s
script performed for more than 3s
commands 'awk' and 'grep' It does not make any significant change on lead time of script.
Please use [code][/code] tags around code and data.
As for the code, my god what a nightmare. If this is run on any server I would be extremely grateful to not be the admin. This is extremely un-maintainable code.
Apart from that, I am not sure I understand what your question is? The timings will depend on the individual machines, so really how many times a particular command can only really be measured by yourself.
Maybe you could add some additional details on what it is you want or need?
The point of writing code of any type is to organize it in a logical fashion, make it readable, reusable, and maintainable. What you've written appears to be none of those.
What exactly are you trying to accomplish with your efforts? In summary English, not code explanations? I'm asking because many times there are a variety of ways to do things and you may be unsuccessfully trying to do something where there is a better set of ways to do so.
How many times command multipath was running if it is N disks from storage?
I'd say N*N times at least, which seems to be confirmed by your calculation, but I have given up dissecting your program somewhere in the middle.
Please use code tags (the button with the "#" sign on it) and indentation when posting programs.
I don't know what your program is supposed to achieve, but there must be a simpler way.
I understand that scare you this piece of code, but the code is entirely worse.
I want to recieve information about which disk from storage has at least one path's await more than 10 miliseconds.
So all code now is:
I have no idea about multipath command, so can you give us an example output from:
Code:
multipath -ll
# and
multipath -a var -ll
Because all of those useless greps can go in one hit and I am positive you would not need all of those awks, and although I may have missed it as again this code is a nightmare, I could not find where the $j variable
from the first loop was ever used.
I understand that scare you this piece of code, but the code is entirely worse.
I want to recieve information about which disk from storage has at least one path's await more than 10 miliseconds.
So all code now is:
Maybe it is much easer way to get that information?
That script performed more than 5 seconds.
Congratulations!
Perhaps it performs better (at least human reviewers perform better) if it's not all on one line?
And indented to reveal the structure better?
As I said, I think this thing has at least quadratic complexity, so it's not surprising the time goes up fast.
What is it supposed to do?
EDIT: I think this is what it is supposed to do:
Quote:
Originally Posted by applehalf
information about which disk from storage has at least one path's await more than 10 miliseconds
I don't quite understand though. Do you mean there are wait times on paths? How do you measure them?
EDIT2: Oh, you use iostat's await column. Well, you run iostat -kNx 1 2, which takes two seconds already. And a multitude of multipath commands in nested loops - no wonder it ends up being 5 secs.
Can you show us the output of a single multipath -ll command? I have a feeling this script has potential for radical simplification.
Last edited by berndbausch; 11-19-2015 at 03:14 AM.
'iostat -kNx 1 2, which takes two seconds already'
It's wrong. This is the output two times in 1 second. First output is statistic for long time, second output for last 1 second:
the output of 'multipath -ll':
DISK1 (UUID_OF_DISK1) dm-1 MY_STORAGE_NAME
size=5.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:18:1 sdb 8:16 active ready running
|- 3:0:6:1 sdw 65:96 active ready running
|- 2:0:20:1 sdg 8:96 active ready running
|- 3:0:13:1 sdab 65:176 active ready running
|- 2:0:21:1 sdl 8:176 active ready running
|- 3:0:27:1 sdag 66:0 active ready running
|- 2:0:22:1 sdq 65:0 active ready running
`- 3:0:29:1 sdal 66:80 active ready running
DISK2 (UUID_OF_DISK2) dm-2 MY_STORAGE_NAME
size=500G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:18:2 sdc 8:32 active ready running
|- 3:0:6:2 sdx 65:112 active ready running
|- 2:0:20:2 sdh 8:112 active ready running
|- 3:0:13:2 sdac 65:192 active ready running
|- 2:0:21:2 sdm 8:192 active ready running
|- 3:0:27:2 sdah 66:16 active ready running
|- 2:0:22:2 sdr 65:16 active ready running
`- 3:0:29:2 sdam 66:96 active ready running
DISK3 (UUID_OF_DISK3) dm-0 MY_STORAGE_NAME
size=5.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:18:0 sda 8:0 active ready running
|- 3:0:6:0 sdv 65:80 active ready running
|- 2:0:20:0 sdf 8:80 active ready running
|- 3:0:13:0 sdaa 65:160 active ready running
|- 2:0:21:0 sdk 8:160 active ready running
|- 3:0:27:0 sdaf 65:240 active ready running
|- 2:0:22:0 sdp 8:240 active ready running
`- 3:0:29:0 sdak 66:64 active ready running
DISK4 (UUID_OF_DISK4) dm-3 MY_STORAGE_NAME
size=4.0T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:18:3 sdd 8:48 active ready running
|- 3:0:6:3 sdy 65:128 active ready running
|- 2:0:20:3 sdi 8:128 active ready running
|- 3:0:13:3 sdad 65:208 active ready running
|- 2:0:21:3 sdn 8:208 active ready running
|- 3:0:27:3 sdai 66:32 active ready running
|- 2:0:22:3 sds 65:32 active ready running
`- 3:0:29:3 sdan 66:112 active ready running
DISK5 (UUID_OF_DISK5) dm-4 MY_STORAGE_NAME
size=4.0T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:18:4 sde 8:64 active ready running
|- 3:0:6:4 sdz 65:144 active ready running
|- 2:0:20:4 sdj 8:144 active ready running
|- 3:0:13:4 sdae 65:224 active ready running
|- 2:0:21:4 sdo 8:224 active ready running
|- 3:0:27:4 sdaj 66:48 active ready running
|- 2:0:22:4 sdt 65:48 active ready running
`- 3:0:29:4 sdao 66:128 active ready running
the result of comand 'multipath -a UUID_OF_DISK1 -ll' will be:
DISK1 (UUID_OF_DISK1) dm-1 MY_STORAGE_NAME
size=5.0G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:18:1 sdb 8:16 active ready running
|- 3:0:6:1 sdw 65:96 active ready running
|- 2:0:20:1 sdg 8:96 active ready running
|- 3:0:13:1 sdab 65:176 active ready running
|- 2:0:21:1 sdl 8:176 active ready running
|- 3:0:27:1 sdag 66:0 active ready running
|- 2:0:22:1 sdq 65:0 active ready running
`- 3:0:29:1 sdal 66:80 active ready running
Does anyone can see variable of my script, which will be much simplier?
As said previously, please use code tags for data as well as code, it will maintain the formatting which may be important to some commands being used.
Can i also ask, is there some sort of sadistic pleasure in mixing up both `` and $(). My suggestion would be to stick with $() as these can be nested if needed.
Note: Not tested.
The iostat will still take two seconds, but the rest will be much faster. And slightly easier to maintain than your code.
Of course, if you want the names of the multipaths in report 2, more work is required.
I am curious as to which stick someone beat you with that you had to echo everything? All of your commands return data, hence the $() will return the same data, then using echo as an extra handler
to print it to screen seems a bit over the top.
Something else I found quite strange was the necessity to reprint the same data further inside the loops:
Although the first prints all names, such as DISK1, the second prints the exact same information that you retrieved at the start of the script.
Also, the simpler form would be:
As you can see, with a little thought you can reduce most of your code to much simpler and more understandable code.
berndbausch has pointed out some alternatives and I would agree that if you indicate the data you are starting with and what the desired output is there would be a much simpler method.
DISK5 (UUID_OF_DISK5) dm-1 FUJITSU,ETERNUS_DX8000
size=4.0T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=130 status=active
|- 2:0:15:2 sdc 8:32 active ready running
|- 3:0:12:2 sdt 65:48 active ready running
|- 2:0:16:2 sdg 8:96 active ready running
|- 3:0:15:2 sdx 65:112 active ready running
|- 2:0:17:2 sdk 8:160 active ready running
|- 3:0:20:2 sdab 65:176 active ready running
|- 2:0:18:2 sdo 8:224 active ready running
`- 3:0:21:2 sdaf 65:240 active ready running
I see that 2 pathes of one disk have await more than 10, so I want to recieve information about DISK5 (but only once, because if I have 20 disks with 16 paths each, and 10 disks have await much then 10 in all pathes, then I want to recieve 10 rows instead of 160).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.