Advertisement
Guest User

Untitled

a guest
Jan 9th, 2020
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.60 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Please note this test requires 30 GB of free space
  4. # in your RAID md device
  5. #
  6. # The aim of this script is to find the best settings for performance
  7. # of your RAID by testing each setting separately.
  8. # This script does make some system modification, but if you don't
  9. # make these changes permanent (e.g. write them in /etc/rc.local)
  10. # At the next boot all the changes will be lost,
  11. # so fill free to play with it!
  12. #
  13. # developed by alfonso / Jan 2012
  14. #
  15. #
  16. # this is your mount point for the RAID
  17. # PLEASE NOTE the script will REMOVE any file called testfile*.out in this folder!!
  18. MNT=/glftpd/site/archive
  19. # this is device from which to get input
  20. # no need to change this
  21. INPUT=/dev/zero
  22.  
  23. # test for priviledges
  24. if [ "$(whoami)" != 'root' ]
  25. then
  26. echo Need to be root!
  27. echo ABORT
  28. exit 1
  29. fi
  30.  
  31. if ! [ -d $MNT/lost+found ]
  32. then
  33. echo
  34. echo "$MNT is not a file system! Something went wrong?"
  35. echo ABORT
  36. exit 1
  37. fi
  38.  
  39. # find out which one is your md
  40. # note that the script only works for one md. If you have more than one
  41. # just uncomment the line below and type something like MDDEV=md0
  42. #MDDEV="`cat /proc/mdstat | grep md | head -1 | awk '{print $1}'`"
  43. MDDEV=md0
  44.  
  45. if [ -z "$MDDEV" ]
  46. then
  47. echo
  48. echo "I can\'t find any md"
  49. echo ABORT
  50. exit 1
  51. fi
  52.  
  53. #
  54. # get the letter of all devices from cat /proc/mdstat
  55. #
  56. # this expression takes the output of /proc/mdstat
  57. # then takes the line of our md
  58. # then changes spaces into new lines
  59. # then takes only lines starting with sd
  60. # then take the 3rd character (a for sda1, etc)
  61. # and then remove new lines to make a single string
  62. DEVS="`cat /proc/mdstat | grep $MDDEV | tr " " "\n" | grep '^sd' | awk '{print substr($0,3,1)}' | tr -d "\n"`"
  63. echo "These are devices found in $MDDEV: $DEVS"
  64.  
  65. function test_write()
  66. {
  67. # writing tests:
  68.  
  69. echo -n .
  70. hdparm -f /dev/sd[$DEVS] > /dev/null
  71. WRTE1=`dd if=$INPUT of=$MNT/testfile1.out bs=100kB count=100000 2>&1 | grep copied`
  72. WRUN1=`echo $WRTE1 | awk ' { print ( $(NF) ) }'`
  73. WRSP1=`echo $WRTE1 | awk ' { print ( $(NF-1) ) }'`
  74. if [ $WRUN1 != "MB/s" ];
  75. then
  76. echo
  77. echo "This script was created for all speeds measured in MB/s"
  78. echo ABORT
  79. exit 1
  80. fi
  81.  
  82. echo -n .
  83. hdparm -f /dev/sd[$DEVS] > /dev/null
  84. WRTE2=`dd if=$INPUT of=$MNT/testfile2.out bs=1MB count=10000 2>&1 | grep copied`
  85. WRUN2=`echo $WRTE2 | awk ' { print ( $(NF) ) }'`
  86. WRSP2=`echo $WRTE2 | awk ' { print ( $(NF-1) ) }'`
  87. if [ $WRUN2 != "MB/s" ];
  88. then
  89. echo
  90. echo "This script was created for all speeds measured in MB/s"
  91. echo ABORT
  92. exit 1
  93. fi
  94.  
  95. echo -n .
  96. hdparm -f /dev/sd[$DEVS] > /dev/null
  97. WRTE3=`dd if=$INPUT of=$MNT/testfile3.out bs=10MB count=1000 2>&1 | grep copied`
  98. WRUN3=`echo $WRTE3 | awk ' { print ( $(NF) ) }'`
  99. WRSP3=`echo $WRTE3 | awk ' { print ( $(NF-1) ) }'`
  100. if [ $WRUN3 != "MB/s" ];
  101. then
  102. echo
  103. echo "This script was created for all speeds measured in MB/s"
  104. echo ABORT
  105. exit 1
  106. fi
  107.  
  108. AVG_WRITE=`echo "($WRSP1+$WRSP2+$WRSP3)*100/3" | bc`
  109.  
  110. #echo " Average write is $AVG_WRITE MB/s NOTE: there should be a dot before the last 2 digits"
  111. echo " average write is `echo "scale=2; $AVG_WRITE / 100;" | bc` MB/s"
  112.  
  113. # echo $WRTE1
  114. # echo $WRTE2
  115. # echo $WRTE3
  116. }
  117.  
  118. function test_read()
  119. {
  120.  
  121. # reading tests:
  122.  
  123. echo -n .
  124. hdparm -f /dev/sd[$DEVS] > /dev/null
  125. READ1=`dd if=$MNT/testfile1.out of=/dev/null bs=100kB count=100000 2>&1 | grep copied`
  126. RDUN1=`echo $READ1 | awk ' { print ( $(NF) ) }'`
  127. RDSP1=`echo $READ1 | awk ' { print ( $(NF-1) ) }'`
  128. if [ $RDUN1 != "MB/s" ];
  129. then
  130. echo
  131. echo "This script was created for all speeds measured in MB/s"
  132. echo ABORT
  133. exit 1
  134. fi
  135.  
  136. echo -n .
  137. hdparm -f /dev/sd[$DEVS] > /dev/null
  138. READ2=`dd if=$MNT/testfile2.out of=/dev/null bs=1MB count=10000 2>&1 | grep copied`
  139. RDUN2=`echo $READ2 | awk ' { print ( $(NF) ) }'`
  140. RDSP2=`echo $READ2 | awk ' { print ( $(NF-1) ) }'`
  141. if [ $RDUN2 != "MB/s" ];
  142. then
  143. echo
  144. echo "This script was created for all speeds measured in MB/s"
  145. echo ABORT
  146. exit 1
  147. fi
  148.  
  149. echo -n .
  150. hdparm -f /dev/sd[$DEVS] > /dev/null
  151. READ3=`dd if=$MNT/testfile3.out of=/dev/null bs=10MB count=1000 2>&1 | grep copied`
  152. RDUN3=`echo $READ3 | awk ' { print ( $(NF) ) }'`
  153. RDSP3=`echo $READ3 | awk ' { print ( $(NF-1) ) }'`
  154. if [ $RDUN3 != "MB/s" ];
  155. then
  156. echo
  157. echo "This script was created for all speeds measured in MB/s"
  158. echo ABORT
  159. exit 1
  160. fi
  161.  
  162. AVG_READ=`echo "($RDSP1+$RDSP2+$RDSP3)*100/3" | bc`
  163.  
  164. #echo " Average read is $AVG_READ MB/s NOTE: there should be a dot before the last 2 digits"
  165. echo " average read is `echo "scale=2; $AVG_READ / 100;" | bc` MB/s"
  166.  
  167. #echo $READ1
  168. #echo $READ2
  169. #echo $READ3
  170. }
  171.  
  172. echo
  173. echo CURRENT SYSTEM SETTINGS
  174. echo your current value of /sys/block/$MDDEV/md/stripe_cache_size is `cat /sys/block/$MDDEV/md/stripe_cache_size`
  175. echo your current value of disk readahead is `blockdev --getra /dev/sd[$DEVS]`
  176. echo your current value of md readahead is `blockdev --getra /dev/$MDDEV`
  177. DEVINDEX=0
  178. NUMDEVS=${#DEVS}
  179. until [ $DEVINDEX -ge $NUMDEVS ]
  180. do
  181. DEVLETTER=${DEVS:$DEVINDEX:1}
  182. echo your current value of /sys/block/sd$DEVLETTER/queue/max_sectors_kb is `cat /sys/block/sd$DEVLETTER/queue/max_sectors_kb`
  183. DEVINDEX=$[$DEVINDEX+1]
  184. done
  185. echo
  186.  
  187. for i in 1 2 3 4
  188. #for i in 1
  189. # 1 when testing /sys/block/$MDDEV/md/stripe_cache_size
  190. # 2 when testing disk readahead
  191. # 3 when testing md readahead
  192. # 4 when testing /sys/block/sdX/queue/max_sectors_kb
  193. do
  194. BEST_WRITE=0
  195. BEST_WRITE_ID=0
  196. WORST_WRITE=0
  197. WORST_WRITE_ID=0
  198. BEST_READ=0
  199. BEST_READ_ID=0
  200. WORST_READ=0
  201. WORST_READ_ID=0
  202. for j in 64 128 256 512 1024 2048 4096 8192 16384
  203. # for j in 64 16384
  204. do
  205. #echo
  206. #echo SYSTEM SETTINGS
  207. #echo your current value of /sys/block/$MDDEV/md/stripe_cache_size is `cat /sys/block/$MDDEV/md/stripe_cache_size`
  208. #echo your current value of disk readahead is `blockdev --getra /dev/sd[$DEVS]`
  209. #echo your current value of md readahead is `blockdev --getra /dev/$MDDEV`
  210. #DEVINDEX=0
  211. #NUMDEVS=${#DEVS}
  212. #until [ $DEVINDEX -ge $NUMDEVS ]
  213. #do
  214. # DEVLETTER=${DEVS:$DEVINDEX:1}
  215. # echo your current value of /sys/block/sd$DEVLETTER/queue/max_sectors_kb is `cat /sys/block/sd$DEVLETTER/queue/max_sectors_kb`
  216. # DEVINDEX=$[$DEVINDEX+1]
  217. #done
  218. #echo
  219. case "$i" in
  220. 1) echo "We are testing md stripe_cache_size"
  221. echo $j > /sys/block/$MDDEV/md/stripe_cache_size
  222. echo "step 1/4: NOW your current value of /sys/block/$MDDEV/md/stripe_cache_size is `cat /sys/block/$MDDEV/md/stripe_cache_size`"
  223. ;;
  224. 2) echo "We are testing disks readahead"
  225. blockdev --setra $j /dev/sd[$DEVS]
  226. echo "step 2/4: NOW your current value of disk readahead is `blockdev --getra /dev/sd[$DEVS]`"
  227. ;;
  228. 3) echo "We are testing md readahead"
  229. blockdev --setra $j /dev/$MDDEV
  230. echo "step 3/4 NOW your current value of md readahead is `blockdev --getra /dev/$MDDEV`"
  231. ;;
  232. 4) echo "We are testing disks max_sectors_kb"
  233. DEVINDEX=0
  234. NUMDEVS=${#DEVS}
  235. until [ $DEVINDEX -ge $NUMDEVS ]
  236. do
  237. DEVLETTER=${DEVS:$DEVINDEX:1}
  238. echo $j > /sys/block/sd$DEVLETTER/queue/max_sectors_kb
  239. echo "step 4/4 NOW your current value of /sys/block/sd$DEVLETTER/queue/max_sectors_kb is `cat /sys/block/sd$DEVLETTER/queue/max_sectors_kb`"
  240. DEVINDEX=$[$DEVINDEX+1]
  241. done
  242. ;;
  243. *) echo "This text should never appear"
  244. echo ABORT
  245. exit 1
  246. ;;
  247. esac
  248. rm $MNT/testfile*.out 2> /dev/null
  249. test_write
  250. if [ "$BEST_WRITE" -eq "0" ]
  251. then
  252. #echo 1st test BEST_WRITE
  253. BEST_WRITE=$AVG_WRITE
  254. BEST_WRITE_ID=$j
  255. fi
  256. if [ "$WORST_WRITE" -eq "0" ]
  257. then
  258. #echo 1st test WORST_WRITE
  259. WORST_WRITE=$AVG_WRITE
  260. WORST_WRITE_ID=$j
  261. fi
  262. if [ "$AVG_WRITE" -ge "$BEST_WRITE" ]
  263. then
  264. echo "found new best write - old: `echo "scale=2; $BEST_WRITE / 100;" | bc` new: `echo "scale=2; $AVG_WRITE / 100;" | bc`"
  265. #echo "old: $BEST_WRITE new: $AVG_WRITE"
  266. BEST_WRITE=$AVG_WRITE
  267. BEST_WRITE_ID=$j
  268. fi
  269. if [ "$AVG_WRITE" -le "$WORST_WRITE" ]
  270. then
  271. echo "found new worst write - old: `echo "scale=2; $WORST_WRITE / 100;" | bc` new: `echo "scale=2; $AVG_WRITE / 100;" | bc`"
  272. #echo old: $WORST_WRITE new: $AVG_WRITE
  273. WORST_WRITE=$AVG_WRITE
  274. WORST_WRITE_ID=$j
  275. fi
  276. test_read
  277. if [ "$BEST_READ" -eq "0" ]
  278. then
  279. #echo 1st test BEST_READ
  280. BEST_READ=$AVG_READ
  281. BEST_READ_ID=$j
  282. fi
  283. if [ "$WORST_READ" -eq "0" ]
  284. then
  285. #echo 1st test WORST_READ
  286. WORST_READ=$AVG_READ
  287. WORST_READ_ID=$j
  288. fi
  289. if [ "$AVG_READ" -ge "$BEST_READ" ]
  290. then
  291. echo "found new best read - old: `echo "scale=2; $BEST_READ / 100;" | bc` new: `echo "scale=2; $AVG_READ / 100;" | bc`"
  292. #echo old: $BEST_READ new: $AVG_READ
  293. BEST_READ=$AVG_READ
  294. BEST_READ_ID=$j
  295. fi
  296. if [ "$AVG_READ" -le "$WORST_READ" ]
  297. then
  298. echo "found new worst read - old: `echo "scale=2; $WORST_READ / 100;" | bc` new: `echo "scale=2; $AVG_READ / 100;" | bc`"
  299. #echo old: $WORST_READ new: $AVG_READ
  300. WORST_READ=$AVG_READ
  301. WORST_READ_ID=$j
  302. fi
  303. rm $MNT/testfile1.out
  304. rm $MNT/testfile2.out
  305. rm $MNT/testfile3.out
  306.  
  307. done
  308. echo BEST_WRITE is $BEST_WRITE
  309. echo BEST_WRITE_ID is $BEST_WRITE_ID
  310. echo WORST_WRITE is $WORST_WRITE
  311. echo WORST_WRITE_ID is $WORST_WRITE_ID
  312. echo BEST_READ is $BEST_READ
  313. echo BEST_READ_ID is $BEST_READ_ID
  314. echo WORST_READ is $WORST_READ
  315. echo WORST_READ_ID is $WORST_READ_ID
  316. # now we want to understand if this test affected more READ or WRITE performances
  317. DIFF_WRITE=$[ BEST_WRITE - WORST_WRITE ]
  318. DIFF_READ=$[ BEST_READ - WORST_READ ]
  319. if [ "$DIFF_READ" -gt "$DIFF_WRITE" ]
  320. then
  321. echo this test affected more READ than WRITE
  322. BEST_OVERALL_ID=$BEST_READ_ID
  323. WORST_OVERALL_ID=$WORST_READ_ID
  324. else
  325. echo this test affected more WRITE than READ
  326. BEST_OVERALL_ID=$BEST_WRITE_ID
  327. WORST_OVERALL_ID=$WORST_WRITE_ID
  328. fi
  329. case "$i" in
  330. 1) echo "$BEST_OVERALL_ID is the OPTIMAL value for md stripe_cache_size"
  331. BEST_1_ID=$BEST_OVERALL_ID
  332. echo $BEST_OVERALL_ID > /sys/block/$MDDEV/md/stripe_cache_size
  333. ;;
  334. 2) echo "$BEST_OVERALL_ID is the OPTIMAL value for disks readahead"
  335. BEST_2_ID=$BEST_OVERALL_ID
  336. blockdev --setra $BEST_OVERALL_ID /dev/sd[$DEVS]
  337. ;;
  338. 3) echo "$BEST_OVERALL_ID is the OPTIMAL value for md readahead"
  339. BEST_3_ID=$BEST_OVERALL_ID
  340. blockdev --setra $BEST_OVERALL_ID /dev/$MDDEV
  341. ;;
  342. 4) echo "$BEST_OVERALL_ID is the OPTIMAL value for max_sectors_kb"
  343. BEST_4_ID=$BEST_OVERALL_ID
  344. DEVINDEX=0
  345. NUMDEVS=${#DEVS}
  346. until [ $DEVINDEX -ge $NUMDEVS ]
  347. do
  348. DEVLETTER=${DEVS:$DEVINDEX:1}
  349. echo $BEST_OVERALL_ID > /sys/block/sd$DEVLETTER/queue/max_sectors_kb
  350. DEVINDEX=$[$DEVINDEX+1]
  351. done
  352. ;;
  353. *) echo "This text should never appear"
  354. echo ABORT
  355. exit 1
  356. ;;
  357. esac
  358. done
  359.  
  360. echo the best for md stripe_cache_size is $BEST_1_ID
  361. echo the best for disks readahead is $BEST_2_ID
  362. echo the best for md readahead is $BEST_3_ID
  363. echo the best for max_sectors_kb is $BEST_4_ID
  364. echo
  365. echo "Add the following lines to your /etc/rc.local"
  366. echo
  367. echo "echo $BEST_1_ID > /sys/block/$MDDEV/md/stripe_cache_size"
  368. echo "blockdev --setra $BEST_2_ID /dev/sd[$DEVS]"
  369. echo "blockdev --setra $BEST_3_ID /dev/$MDDEV"
  370. DEVINDEX=0
  371. NUMDEVS=${#DEVS}
  372. until [ $DEVINDEX -ge $NUMDEVS ]
  373. do
  374. DEVLETTER=${DEVS:$DEVINDEX:1}
  375. echo "echo $BEST_4_ID > /sys/block/sd$DEVLETTER/queue/max_sectors_kb"
  376. DEVINDEX=$[$DEVINDEX+1]
  377. done
  378.  
  379. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement