From 436f6e63072f3537e66cef87dd8f6ae776dd0454 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 11 Sep 2019 17:08:18 +0200 Subject: port building of redis to python --- src/benchmarks/redis.py | 52 +++++++++++++++++++++++++++++++++++++++++++ src/benchmarks/redis/Makefile | 20 ----------------- 2 files changed, 52 insertions(+), 20 deletions(-) delete mode 100644 src/benchmarks/redis/Makefile diff --git a/src/benchmarks/redis.py b/src/benchmarks/redis.py index 945d3a0..689a9b6 100644 --- a/src/benchmarks/redis.py +++ b/src/benchmarks/redis.py @@ -17,13 +17,19 @@ """Definition of the redis benchmark""" +import os import re +import subprocess +import sys +from urllib.request import urlretrieve from src.benchmark import Benchmark +from src.util import print_info, download_reporthook REQUESTS_RE = re.compile("(?P(\\d*.\\d*)) requests per second") + class BenchmarkRedis(Benchmark): """Redis benchmark @@ -41,6 +47,52 @@ class BenchmarkRedis(Benchmark): super().__init__(name) + def prepare(self): + super().prepare() + + redis_version = "5.0.5" + redis_archive = f"redis-{redis_version}.tar.gz" + redis_url = f"http://download.redis.io/releases/{redis_archive}" + redis_dir = os.path.join(self.build_dir, f"redis-{redis_version}") + + if not os.path.isdir(redis_dir): + if not os.path.isfile(redis_archive): + print(f"Downloading redis-{redis_version}...") + urlretrieve(redis_url, redis_archive, download_reporthook) + sys.stderr.write("\n") + + # Create build_dir + os.mkdir(self.build_dir) + + # Extract redis + proc = subprocess.run(["tar", "Cxf", self.build_dir, redis_archive], + # stdout=subprocess.PIPE, stderr=subprocess.PIPE, + universal_newlines=True) + + # delete archive + if proc.returncode == 0: + os.remove(redis_archive) + else: + return False + + # building redis + proc = subprocess.run(["make", "-C", redis_dir], + # stdout=subprocess.PIPE, stderr=subprocess.PIPE, + universal_newlines=True) + + if proc.returncode != 0: + return False + + + # create symlinks + for exe in ["redis-cli", "redis-server", "redis-benchmark"]: + src = os.path.join(redis_dir, "src", exe) + dest = os.path.join(self.build_dir, exe) + os.link(src, dest) + + return True + + @staticmethod def process_output(result, stdout, stderr, allocator, perm): result["requests"] = REQUESTS_RE.search(stdout).group("requests") diff --git a/src/benchmarks/redis/Makefile b/src/benchmarks/redis/Makefile deleted file mode 100644 index de72342..0000000 --- a/src/benchmarks/redis/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -OBJDIR ?= obj - -unexport CC -unexport CXX -unexport WARNFLAGS -unexport COMMONFLAGS -unexport OPTFLAGS -unexport CFLAGS -unexport CXXFLAGS -unexport LDFLAGS -unexport LDXXFLAGS - -.PHONY = all clean - -all: - @echo building redis benchmark - ./build.sh $(OBJDIR) $(REDIS_VERSION) - -clean: - rm -rf $(OBJDIR) -- cgit v1.2.3