Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ make pytest # run flow tests using RLTest
CLUSTER=1 # run general tests on a OSS Redis Cluster topology
VALGRIND|VG=1 # run specified tests with Valgrind
VERBOSE=1 # display more RLTest-related information
MEMINFO=1 # show memory information

make pack # build package (RAMP file)

Expand Down
3 changes: 3 additions & 0 deletions sbin/system-setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def common_first(self):
self.run("%s/bin/getrust" % READIES)
self.run("%s/bin/getcmake" % READIES)

def linux(self):
self.install("procps")

def debian_compat(self):
self.run("%s/bin/enable-utf8" % READIES)
self.run("%s/bin/getgcc" % READIES)
Expand Down
30 changes: 29 additions & 1 deletion tests/pytest/common.py
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
Expand All @@ -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))

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @oshadmi

Copy link
Copy Markdown
Contributor Author

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() (with RLTest --debug-print) and got such a load of irrelevant garbage that I immediately reverted to print() (with MEMINFO=1). This is what happens when Truth (c) collides with user experience.

Copy link
Copy Markdown

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 use debugPrint you will get those prints when you run with -vv.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

mem = envMem(env)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use info memory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?
In most cases you'll be measuring vsz anyway so why not use it in the first place?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info memory gives you both RSS and the memory Redis think it consumes so I do not see why not use it instead of using env.envRunner.masterProcess.pid which is internal to RLTest and might change someday and break this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
11 changes: 9 additions & 2 deletions tests/pytest/includes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

import sys
import json
import os
from RLTest import Defaults
import psutil
import re
import redis
import signal
import sys
import time

from RLTest import Defaults, Env

Defaults.decode_responses = True

Expand Down
7 changes: 1 addition & 6 deletions tests/pytest/test_keyspace_notifications.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import json

import time
from common import *

import redis
from RLTest import Env,Defaults
import time
Defaults.decode_responses = True

def assert_msg(env, msg, expected_type, expected_data):
env.assertEqual(expected_type, msg['type'])
Expand Down
89 changes: 89 additions & 0 deletions tests/pytest/test_mem.py
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 = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not run the tests both with serde_json and ijson?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but they do. when we run with serde_json, SERDE_JSON env var is 1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a full cycle of tests running with JSON_BACKEND SERDE_JSON, and when this is the case, we'll be testing it's memory usage. Otherwise, we'll be doing both backends on each cycle, which is redundant and somewhat confusing.

]


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'])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here and other print - do we always want to print?
What is vsz0 in right-hand-side of vsz0=vsz0 ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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)}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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()
11 changes: 1 addition & 10 deletions tests/pytest/test_multi.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# -*- coding: utf-8 -*-

import sys
import os
import redis
import json
from RLTest import Env
from includes import *

from RLTest import Defaults

Defaults.decode_responses = True
from common import *

# ----------------------------------------------------------------------------------------------

Expand Down
11 changes: 3 additions & 8 deletions tests/pytest/test_short_read.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# encoding=utf-8
import json
import os

from common import *

import random
import subprocess
import tempfile
import zipfile

import gevent.queue
import gevent.server
import gevent.socket
import time
from RLTest import Defaults
from enum import Enum, auto
from common import TimeLimit


Defaults.decode_responses = True

CREATE_INDICES_TARGET_DIR = '/tmp/test'
BASE_RDBS_URL = 'https://s3.amazonaws.com/redismodules/redisearch-enterprise/rdbs/'
Expand Down
29 changes: 19 additions & 10 deletions tests/pytest/tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

[[ $IGNERR == 1 ]] || set -e
# [[ $VERBOSE == 1 ]] && set -x
# [[ $IGNERR == 1 ]] || set -e
Comment thread
rafie marked this conversation as resolved.
Resolved

HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
export ROOT=$(cd $HERE/../.. && pwd)
Expand All @@ -15,9 +15,9 @@ cd $HERE
help() {
cat <<-END
Run Python tests

[ARGVARS...] tests.sh [--help|help] [<module-so-path>]

Argument variables:
MODULE=path Path to redisai.so
TEST=test Run specific test (e.g. test.py:test_name)
Expand All @@ -31,11 +31,13 @@ help() {

VALGRIND|VG=1 Run with Valgrind
SAN=type Use LLVM sanitizer (type=address|memory|leak|thread)
MEMINFO=1 Show memory information

VERBOSE=1 Print commands
IGNERR=1 Do not abort on error
NOP=1 Dry run
LOG=0|1 Write to log
LOG=1 Write to log
QUIET=1 Be less verbose

END
}
Expand All @@ -52,7 +54,7 @@ install_git_lfs() {

setup_redis_server() {
if [[ -n $SAN ]]; then
if [[ $SAN == addr || $SAN == address ]]; then
if [[ $SAN == address ]]; then
REDIS_SERVER=${REDIS_SERVER:-redis-server-asan-6.2}
if ! command -v $REDIS_SERVER > /dev/null; then
echo Building Redis for clang-asan ...
Expand All @@ -62,7 +64,7 @@ setup_redis_server() {
export ASAN_OPTIONS=detect_odr_violation=0
# :detect_leaks=0

elif [[ $SAN == mem || $SAN == memory ]]; then
elif [[ $SAN == memory ]]; then
REDIS_SERVER=${REDIS_SERVER:-redis-server-msan-6.2}
if ! command -v $REDIS_SERVER > /dev/null; then
echo Building Redis for clang-msan ...
Expand Down Expand Up @@ -90,6 +92,8 @@ setup_redis_server() {
#----------------------------------------------------------------------------------------------

valgrind_config() {
export VALGRIND=1 # for RLTest

export VG_OPTIONS="
-q \
--leak-check=full \
Expand Down Expand Up @@ -123,7 +127,7 @@ run_tests() {
local title="$1"
shift
if [[ -n $title ]]; then
$READIES/bin/sep -0
$READIES/bin/sep
printf "Testing $title:\n\n"
fi

Expand Down Expand Up @@ -200,7 +204,7 @@ run_tests() {

#----------------------------------------------------------------------------------------------

[[ $1 == --help || $1 == help ]] && { help; exit 0; }
[[ $1 == --help || $1 == help || $HELP == 1 ]] && { help; exit 0; }

GDB=${GDB:-0}

Expand Down Expand Up @@ -229,9 +233,9 @@ MODULE=${MODULE:-$1}

[[ $VALGRIND == 1 ]] && valgrind_config

if [[ ! -z $TEST ]]; then
if [[ -n $TEST ]]; then
RLTEST_ARGS+=" --test $TEST"
if [[ $LOG != 1 ]]; then
if [[ $LOG != 1 && $QUIET != 1 ]]; then
RLTEST_ARGS+=" -s"
export BB=${BB:-1}
fi
Expand All @@ -243,6 +247,11 @@ fi

export OS=$($READIES/bin/platform --os)

if [[ -n $SAN ]]; then
# for RLTest
export SANITIZER="$SAN"
fi

#----------------------------------------------------------------------------------------------

cd $ROOT/tests/pytest
Expand Down