bench.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/bash
  2. readonly messageSize="${1:-200}"
  3. readonly batchSize="${2:-200}"
  4. readonly memQueueSize="${3:-1000000}"
  5. readonly dataPath="${4:-}"
  6. set -e
  7. set -u
  8. echo "# using --mem-queue-size=$memQueueSize --data-path=$dataPath --size=$messageSize --batch-size=$batchSize"
  9. echo "# compiling/running nsqd"
  10. pushd apps/nsqd >/dev/null
  11. go build
  12. rm -f *.dat
  13. ./nsqd --mem-queue-size=$memQueueSize --data-path=$dataPath >/dev/null 2>&1 &
  14. nsqd_pid=$!
  15. popd >/dev/null
  16. cleanup() {
  17. kill -9 $nsqd_pid
  18. rm -f nsqd/*.dat
  19. }
  20. trap cleanup INT TERM EXIT
  21. sleep 0.3
  22. echo "# creating topic/channel"
  23. curl --silent 'http://127.0.0.1:4151/create_topic?topic=sub_bench' >/dev/null 2>&1
  24. curl --silent 'http://127.0.0.1:4151/create_channel?topic=sub_bench&channel=ch' >/dev/null 2>&1
  25. echo "# compiling bench_reader/bench_writer"
  26. pushd bench >/dev/null
  27. for app in bench_reader bench_writer; do
  28. pushd $app >/dev/null
  29. go build
  30. popd >/dev/null
  31. done
  32. popd >/dev/null
  33. echo -n "PUB: "
  34. bench/bench_writer/bench_writer --size=$messageSize --batch-size=$batchSize 2>&1
  35. curl -s -o cpu.pprof http://127.0.0.1:4151/debug/pprof/profile &
  36. pprof_pid=$!
  37. echo -n "SUB: "
  38. bench/bench_reader/bench_reader --size=$messageSize --channel=ch 2>&1
  39. echo "waiting for pprof..."
  40. wait $pprof_pid