sh Docker负载测试

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Docker负载测试相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# nifty function copied from stackoverflow
kill_descendant_processes() {
    local pid="$1"
    local and_self="${2:-false}"
    if children="$(pgrep -P "$pid")"; then
        for child in $children; do
            kill_descendant_processes "$child" true
        done
    fi
    if [[ "$and_self" == true ]]; then
        echo "killing $pid"
        kill  -9 "$pid"
    fi
}

echo "Starting program at $(date)"
container_prefix=$1
# Spin 500 subprocess in parallel in background simulating 500 tasks sent to mesos slave/agent
# each of these subprocess then spawns another child subprocess in background that does docker run while it monitors the creation of the container
# if container creation not detected after a while, the subprocess kills all its child and its grandchild. So, both the child subprocess and docker process will get killed
# this closely mimics the mesos docker containerizer and mesos docker executor model
# program terminates when all subprocess exits
for count in {1..500}
do
(
   (
      docker pull nginx:latest
      echo "Launching container ${container_prefix}_$count on $(date)"
      docker run -p 80 --name ${container_prefix}_$count nginx
   ) &

   COUNT=0
   while true; do
     sleep 1
     docker inspect ${container_prefix}_$count > /dev/null
     if [ $? -eq 0 ]; then
          break
     fi
     let COUNT=COUNT+1
     if [ $COUNT -gt 210 ]; then
         echo "##################### Aborting tries of ${container_prefix}_$count at $(date)"
         docker stop ${container_prefix}_$count
         kill_descendant_processes $BASHPID
         break
     fi
   done


)&
done
wait
echo "all work done at $(date)"

以上是关于sh Docker负载测试的主要内容,如果未能解决你的问题,请参考以下文章

sh MarkLogic负载测试信息

sh 围攻,http负载测试

sh Cassandra docker Cluster用于测试

用docker搭建nginx负载均衡测试环境

Docker Selenium Grid 全量集成测试环境搭建和负载均衡

Docker Selenium Grid 全量集成测试环境搭建和负载均衡