dbench_monitor 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env bash
  2. #
  3. #(c) 2004-present, Facebook Inc. All rights reserved.
  4. #
  5. #see LICENSE file for more information on use/redistribution rights.
  6. #
  7. #
  8. #dbench_monitor: monitor db_bench process for violation of memory utilization
  9. #
  10. #default usage will monitor 'virtual memory size'. See below for standard options
  11. #passed to db_bench during this test.
  12. #
  13. # See also: ./pflag for the actual monitoring script that does the work
  14. #
  15. #NOTE:
  16. # You may end up with some /tmp/ files if db_bench OR
  17. # this script OR ./pflag was killed unceremoniously
  18. #
  19. # If you see the script taking a long time, trying "kill"
  20. # will usually cleanly exit.
  21. #
  22. #
  23. DIR=`dirname $0`
  24. LOG=/tmp/`basename $0`.$$
  25. DB_BENCH="$DIR/../db_bench";
  26. PFLAG=${DIR}/pflag
  27. usage() {
  28. cat <<HELP; exit
  29. Usage: $0 [-h]
  30. -h: prints this help message
  31. This program will run the db_bench script to monitor memory usage
  32. using the 'pflag' program. It launches db_bench with default settings
  33. for certain arguments. You can change the defaults passed to
  34. 'db_bench' program, by setting the following environment
  35. variables:
  36. bs [block_size]
  37. ztype [compression_type]
  38. benches [benchmarks]
  39. reads [reads]
  40. threads [threads]
  41. cs [cache_size]
  42. vsize [value_size]
  43. comp [compression_ratio]
  44. num [num]
  45. See the code for more info
  46. HELP
  47. }
  48. [ ! -x ${DB_BENCH} ] && echo "WARNING: ${DB_BENCH} doesn't exist, abort!" && exit -1;
  49. [ "x$1" = "x-h" ] && usage;
  50. trap 'rm -f ${LOG}; kill ${PID}; echo "Interrupted, exiting";' 1 2 3 15
  51. touch $LOG;
  52. : ${bs:=16384}
  53. : ${ztype:=zlib}
  54. : ${benches:=readwhilewriting}
  55. : ${reads:=$((1*1024*1024))};
  56. : ${threads:=8}
  57. : ${vsize:=2000}
  58. : ${comp:=0.5}
  59. : ${num:=10000}
  60. : ${cs:=$((1*1024*1024*1024))};
  61. DEBUG=1 #Set to 0 to remove chattiness
  62. if [ "x$DEBUG" != "x" ]; then
  63. #
  64. #NOTE: under some circumstances, --use_existing_db may leave LOCK files under ${TMPDIR}/rocksdb/*
  65. #cleanup the dir and re-run
  66. #
  67. echo DEBUG: Will run $DB_BENCH --block_size=$bs --compression_type=$ztype --benchmarks="$benches" --reads="$reads" --threads="$threads" --cache_size=$cs --value_size=$vsize --compression_ratio=$comp --num=$num --use_existing_db
  68. fi
  69. $DB_BENCH --block_size=$bs --compression_type=$ztype --benchmarks="$benches" --reads="$reads" --threads="$threads" --cache_size=$cs --value_size=$vsize --compression_ratio=$comp --num=$num --use_existing_db >$LOG 2>&1 &
  70. if [ $? -ne 0 ]; then
  71. warn "WARNING: ${DB_BENCH} did not launch successfully! Abort!";
  72. exit;
  73. fi
  74. PID=$!
  75. #
  76. #Start the monitoring. Default is "vsz" monitoring for upto cache_size ($cs) value of virtual mem
  77. #You could also monitor RSS and CPUTIME (bsdtime). Try 'pflag -h' for how to do this
  78. #
  79. ${PFLAG} -p $PID -v
  80. rm -f $LOG;