diff --git a/examples/tuning/redis/README.md b/examples/tuning/redis/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f825eebc41f7f6450f5addedc2f5194bbc8b3ea1 --- /dev/null +++ b/examples/tuning/redis/README.md @@ -0,0 +1,27 @@ +# Deployment script for Redis and its benchmark + +Before running the script, you may want to read this guide first. + +The goal is to deploy redis-server on localhost, redis-benchmark on another host for future tunning work. + +## Deploy ⚙️ + +To run the script, execute `bash prepare.sh`. + +1. Enter the IP address and port number(skip to default) of the redis-server host. +2. Enter the IP address of the redis-benchmark host. +3. Enter 'y' to generate and deploy the new SSH key on the benchmark host, or skip if the SSH key is configured. +4. Enter the password for access benchmark host. + +That is all you need to interact with the script. + +## Benchmark ⏱️ + +To start the benchmark, execute `bash benchmark.sh`, the localhost will access the benchmark host and trigger it. + +The benchmark host will transfer the log file to localhost after the benchmark. + +## To contact ✉️ + +- Email: yingjie@isrc.iscas.ac.cn +- Gitee: https://gitee.com/shangyingjie diff --git a/examples/tuning/redis/benchmark.py b/examples/tuning/redis/benchmark.py new file mode 100644 index 0000000000000000000000000000000000000000..94270f6d2cab90b695fc877df8d1788695cbe5f8 --- /dev/null +++ b/examples/tuning/redis/benchmark.py @@ -0,0 +1,56 @@ +#!/usr/bin/python3 + +# Copyright (c) 2022 Huawei Technologies Co., Ltd. +# A-Tune is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. + +# ############################################# +# @Author : shangyingjie +# @Contact : yingjie@isrc.iscas.ac.cn +# @Date : 2022/3/6 +# @License : Mulan PSL v2 +# @Desc : Redis benchmark script +# ############################################# + +import subprocess +import os + + +def get_output(cmd: str): + """ + Return the result of executing a command. + """ + output = subprocess.run(cmd, shell=True, capture_output=True, text=True) + return output.returncode, output.stdout + + +if __name__ == '__main__': + os.chdir(os.path.dirname(os.path.abspath(__file__))) + redis_server_ip = 'will be replaced after running prepare.sh' + redis_server_port = 'will be replaced after running prepare.sh' + retcode, stdoutput = get_output( + f"redis-cli -h {redis_server_ip} -p {redis_server_port} ping") + if retcode != 0: + print("failed to access redis-server!") + exit(1) + else: + print("access redis-server successfully.") + + print("start test...") + retcode, benchmark_csv = get_output( + f"redis-benchmark -h {redis_server_ip} -p {redis_server_port} -t set,get,incr,rpop,sadd,hset,lrange_600 --csv") + + total_queries = 0 + for line in benchmark_csv.splitlines(): + total_queries += float(line.split(',')[1].replace('"', '')) + + result = benchmark_csv + "\n" + f"total queries: {total_queries}" + print(result) + with open("redis_benchmark.log", "w") as f: + f.write(result) diff --git a/examples/tuning/redis/prepare.sh b/examples/tuning/redis/prepare.sh new file mode 100644 index 0000000000000000000000000000000000000000..9592a90a3c538a60548f0387e72dd706bd8d2825 --- /dev/null +++ b/examples/tuning/redis/prepare.sh @@ -0,0 +1,72 @@ +#!/usr/bin/bash + +# Copyright (c) 2022 Huawei Technologies Co., Ltd. +# A-Tune is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. + +############################################# +# @Author : shangyingjie +# @Contact : yingjie@isrc.iscas.ac.cn +# @Date : 2022/3/6 +# @License : Mulan PSL v2 +# @Desc : Redis deployment script +# ############################################# + +cd "$(dirname "$0")" + +while [[ -z "$redis_server_ip" ]]; do + read -p "please input redis-server(localhost) IP:" redis_server_ip +done +read -p "please input port for redis-server(localhost), or skip with default port number(6379):" redis_server_port +if [ -z "$redis_server_port" ]; then + redis_server_port=6379 +fi +while [[ -z "$redis_benchmark_ip" ]]; do + read -p "please input an another host IP to install redis-benchmark(SSH required):" redis_benchmark_ip +done +# read -p "please input port for redis-server(localhost), or skip with default port number(6379):" redis_server_port +read -p "enter y to set up new ssh keys for the redis-benchmark host or skip if deployed." choice +if [ "$choice" = "y" ]; then + ssh-keygen -t rsa -f benchmark_host_key -N "" + ssh-copy-id -i benchmark_host_key root@"$redis_benchmark_ip" +fi + +echo "install redis-server..." +yum install -y redis + +echo "update redis_benchmark.sh and benchmark.py with value just entered..." +sed -i "s#redis_server_ip=.*#redis_server_ip=$redis_server_ip#g" redis_benchmark.sh +sed -i "s#redis_server_ip = .*#redis_server_ip = '$redis_server_ip'#g" benchmark.py +sed -i "s#redis_server_port=.*#redis_server_port=$redis_server_port#g" redis_benchmark.sh +sed -i "s#redis_server_port = .*#redis_server_port = '$redis_server_port'#g" benchmark.py +sed -i "s#redis_benchmark_ip=.*#redis_benchmark_ip=$redis_benchmark_ip#g" redis_benchmark.sh + +echo "copy benchmark scripts to" "$redis_benchmark_ip" +if [ "$choice" = "y" ]; then + scp -i benchmark_host_key benchmark.py root@"$redis_benchmark_ip":/root/ +else + scp benchmark.py root@"$redis_benchmark_ip":/root/ +fi + +echo "deploy redis-benchmark on:" "$redis_benchmark_ip" +if [ "$choice" = "y" ]; then + ssh -i benchmark_host_key -t root@"$redis_benchmark_ip" "yum install -y redis;" +else + ssh -t root@"$redis_benchmark_ip" "yum install -y redis;" +fi + +echo "start redis-server..." +systemctl start redis.service + +echo "modify bind port to 0.0.0.0 to allow redis-benchmark access." +sed -i 's/bind 127.0.0.1/bind 0.0.0.0/g' /etc/redis.conf +systemctl restart redis.service + +echo "copy the server yaml file to /etc/atuned/tuning/" +cp ./redis_benchmark_server.yaml /etc/atuned/tuning/ diff --git a/examples/tuning/redis/redis_benchmark.sh b/examples/tuning/redis/redis_benchmark.sh new file mode 100644 index 0000000000000000000000000000000000000000..43a100d7e338f955d1d66d650f7b6da6533a2a97 --- /dev/null +++ b/examples/tuning/redis/redis_benchmark.sh @@ -0,0 +1,30 @@ +#!/usr/bin/bash +# Copyright (c) 2020 Huawei Technologies Co., Ltd. +# A-Tune is licensed under the Mulan PSL v2. +# You can use this software according to the terms and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# http://license.coscl.org.cn/MulanPSL2 +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +# PURPOSE. +# See the Mulan PSL v2 for more details. + +############################################# +# @Author : shangyingjie +# @Contact : yingjie@isrc.iscas.ac.cn +# @Date : 2022/3/6 +# @License : Mulan PSL v2 +# @Desc : Redis benchmark trigger script +# ############################################# + +echo 'triggering benchmark...' +cd "$(dirname "$0")" + +redis_benchmark_ip='will be replaced after running prepare.sh' +if [ -f "./benchmark_host_key" ]; then + ssh -i benchmark_host_key root@"$redis_benchmark_ip" -t "/usr/bin/python3 /root/benchmark.py" + scp -i benchmark_host_key root@"$redis_benchmark_ip":/root/redis_benchmark.log ./ +else + ssh root@"$redis_benchmark_ip" -t "/usr/bin/python3 /root/benchmark.py" + scp root@"$redis_benchmark_ip":/root/redis_benchmark.log ./ +fi diff --git a/examples/tuning/redis/redis_benchmark_client.yaml b/examples/tuning/redis/redis_benchmark_client.yaml new file mode 100644 index 0000000000000000000000000000000000000000..07fba4760ccbecff0617ce605d86a519682110cf --- /dev/null +++ b/examples/tuning/redis/redis_benchmark_client.yaml @@ -0,0 +1,14 @@ +project: "redis_benchmark" +engine: "gbrt" +iterations: 50 +random_starts: 10 + +benchmark: "bash redis/redis_benchmark.sh" + +evaluations : + - + name: "QPS" + info: + get: "grep 'total queries' redis_benchmark.log | awk '{print $3}'" + type: "negative" + weight: 100 \ No newline at end of file