Repository navigation
Added memory consumption test #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
51ea4a4
805cad9
408dc4b
906431f
4831af2
8669699
310bfb2
de6dc17
092b39a
3b5b000
92b9cca
f0f34ff
b9851a3
5cd1c4e
9a92764
a111739
9ad82b4
67c088b
5f309fc
0bce6e6
99c8145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,13 @@ | ||
| import signal | ||
|
|
||
| from contextlib import contextmanager | ||
| from includes import * | ||
|
|
||
| SANITIZER = os.getenv('SANITIZER', '') # typically 'address' or 'memory' | ||
| VALGRIND = os.getenv('VALGRIND', '0') == '1' | ||
| CODE_COVERAGE = os.getenv('CODE_COVERAGE', '0') == '1' | ||
|
|
||
| MEMINFO = os.getenv('MEMINFO', '0') == '1' | ||
| SERDE_JSON = os.getenv('SERDE_JSON', '0') == '1' | ||
|
|
||
|
|
||
| @contextmanager | ||
|
|
@@ -14,3 +22,23 @@ def handler(signum, frame): | |
| finally: | ||
| signal.setitimer(signal.ITIMER_REAL, 0) | ||
| signal.signal(signal.SIGALRM, signal.SIG_DFL) | ||
|
|
||
| def envMem(env): | ||
| pid = env.envRunner.masterProcess.pid | ||
| meminfo = psutil.Process(pid).memory_info() | ||
| vms = meminfo.vms / 1024 | ||
| rss = meminfo.rss / 1024 | ||
| return {'vsz': vms, 'rss': rss } | ||
|
|
||
| def checkEnvMem(env, expected_vsz=None, vsz0=0, threshold=0.1, title=None): | ||
| if MEMINFO: | ||
| if title is not None: | ||
| print(f"--- {title}") | ||
| pid = env.envRunner.masterProcess.pid | ||
| print(paella.sh(f'cat /proc/{pid}/status | grep ^Vm', join=False)) | ||
| mem = envMem(env) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you prefer redis-server internal indications over system ones when investigating memory issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
| vsz = mem['vsz'] - vsz0 | ||
| if expected_vsz is not None: | ||
| env.assertGreater(vsz, expected_vsz * (1 - threshold)) | ||
| env.assertLess(vsz, expected_vsz * (1 + threshold)) | ||
| return vsz | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
|
|
||
| from common import * | ||
| import time | ||
| import datetime | ||
|
|
||
|
|
||
| CHECK_MEMRECLAIM = os.getenv('MEMRECLAIM', '0') == '1' | ||
|
|
||
| JSON_FILES = [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rafie I think it's better to copy these files so it won't change without us knowing about it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They can become quite big and I don't want to introduce git-lfs. When it breaks, we'll fix it. |
||
| {'file': 'https://raw.githubusercontent.com/mloskot/json_benchmark/master/data/canada.json', | ||
| 'vsz': 2880000 if SERDE_JSON else 598000}, | ||
| {'file': 'https://raw.githubusercontent.com/RichardHightower/json-parsers-benchmark/master/data/citm_catalog.json', | ||
| 'vsz': 847000 if SERDE_JSON else 200000}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not run the tests both with serde_json and ijson?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but they do. when we run with serde_json, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant why you want to control it from outside and not just run on both here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a full cycle of tests running with |
||
| ] | ||
|
|
||
|
|
||
| class TestMem: | ||
| def __init__(self): | ||
| self.env = Env() | ||
| for jfile in JSON_FILES: | ||
| path = paella.wget(jfile['file'], tempdir=True) | ||
| jfile['path'] = path | ||
| with open(path) as jsonfile: | ||
| jfile['doc'] = jsonfile.read() | ||
|
|
||
| def __del__(self): | ||
| for jfile in JSON_FILES: | ||
| os.unlink(jfile['path']) | ||
|
|
||
| def testKeys(self): | ||
| env = self.env | ||
| env.skipOnCluster() | ||
| if env.useAof or env.useSlaves or SANITIZER != '': | ||
| env.skip() | ||
|
|
||
| def add_and_check(title): | ||
| t0 = time.monotonic() | ||
| for i in range(0, 100): | ||
| env.execute_command('json.set', f'json{i}', '$', jfile['doc']) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make jfile as an argument to the function, its not clear where it is coming from..
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's coming from the closure, but I can add. |
||
| title += f" t={datetime.timedelta(seconds=time.monotonic() - t0)}" | ||
| checkEnvMem(env, expected_vsz=jfile['vsz'], vsz0=vsz0, title=title) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here and other
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a named argument. |
||
| def delete(): | ||
| t0 = time.monotonic() | ||
| for i in range(0, 100): | ||
| env.execute_command('json.del', f'json{i}') | ||
| print(f"--- del: t={datetime.timedelta(seconds=time.monotonic() - t0)}") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. env.debug_print maybe? |
||
|
|
||
| fi = 0 | ||
| for jfile in JSON_FILES: | ||
| fi += 1 | ||
| vsz0 = checkEnvMem(env, title=f"before (keys {fi})") | ||
| add_and_check(f"add (keys {fi})") | ||
| if CHECK_MEMRECLAIM: | ||
| delete() | ||
| add_and_check(f"add after del (keys {fi})") | ||
| env.execute_command('flushall') # so no .rdb file is created | ||
| env.stop() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also check mem here? Should be the initial mem before adding any key?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redis does not give memory back that easily. It's hard to get a consistent behavior (not like with fields, where we manage memory ourselves). |
||
| env.start() | ||
|
|
||
| def testFields(self): | ||
| env = self.env | ||
| env.skipOnCluster() | ||
| if env.useAof or env.useSlaves or SANITIZER != '': | ||
| env.skip() | ||
|
|
||
| def add_and_check(title): | ||
| t0 = time.monotonic() | ||
| env.execute_command('json.set', 'json', '.', '{}') | ||
| for i in range(0, 100): | ||
| env.execute_command('json.set', 'json', f'$.json{i}', jfile['doc']) | ||
| title += f" t={datetime.timedelta(seconds=time.monotonic() - t0)}" | ||
| checkEnvMem(env, expected_vsz=jfile['vsz'], vsz0=vsz0, title=title) | ||
| def delete(): | ||
| t0 = time.monotonic() | ||
| for i in range(0, 100): | ||
| env.execute_command('json.del', 'json', f'json{i}') | ||
| env.debugPrint(f"--- del: t={datetime.timedelta(seconds=time.monotonic() - t0)}") | ||
|
|
||
| fi = 0 | ||
| for jfile in JSON_FILES: | ||
| fi += 1 | ||
| vsz0 = checkEnvMem(env, title=f"before (fields {fi})") | ||
| add_and_check(f"add (fields {fi})") | ||
| if CHECK_MEMRECLAIM: | ||
| delete() | ||
| add_and_check(f"add after del (fields {fi})") | ||
| env.execute_command('flushall') # so no .rdb file is created | ||
| env.stop() | ||
| env.start() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we always want to print? Maybe use
env.debugPrint?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs only with
MEMINFO=1.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @oshadmi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I tried
env.debugPrint()(withRLTest --debug-print) and got such a load of irrelevant garbage that I immediately reverted toprint()(withMEMINFO=1). This is what happens when Truth (c) collides with user experience.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still its better to us
debugPrint, debug prints should be verbose, you only enable it when you want better logging for debug. Also if you usedebugPrintyou will get those prints when you run with-vv.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.