From a331c012d220a631213ceabad150ce0959dd9bb4 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Wed, 5 Sep 2018 18:24:48 +0530 Subject: [PATCH] [minor] redis: fix max memory size some macOS systems do not have SC_PHYS_PAGES set and may raise a ValueError. As a workaround, we fallback to sysctl. --- bench/config/redis.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bench/config/redis.py b/bench/config/redis.py index 6a32927e..deb860af 100644 --- a/bench/config/redis.py +++ b/bench/config/redis.py @@ -67,10 +67,8 @@ def get_redis_version(): return float('{major}.{minor}'.format(major=version.major, minor=version.minor)) def get_max_redis_memory(): - total_virtual_mem = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')/(pow(1024, 2)) - max_memory = int(total_virtual_mem * 0.05) # Max memory for redis is 5% of virtual memory - - if max_memory < 50: - return 50 - else: - return max_memory + try: + max_mem = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') + except ValueError: + max_mem = int(subprocess.check_output(['sysctl', '-n', 'hw.memsize']).strip()) + return max(50, int((max_mem / (1024. ** 2)) * 0.05))