Skip to content
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

chor(benchmark): create basic Python control #3106

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
99 changes: 99 additions & 0 deletions tools/benchmark/runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
import os
from typing import List

import attr
from kubernetes import client, config, watch
from kubernetes.client import models


@attr.define
class TestCase:
name: str
timeout: int = 6000


TEST_CASES: List[TestCase] = [TestCase(name="default")]

config.load_kube_config()
v1 = client.BatchV1Api()


def wait_for_job_completion(namespace: str, job_name: str, timeout_seconds: int):
w = watch.Watch()
try:
for event in w.stream(
v1.list_namespaced_job, namespace=namespace, timeout_seconds=timeout_seconds
):
job = event["object"] # type: ignore

if job.metadata.name != job_name: # type: ignore
continue

conditions = job.status.conditions # type: ignore
if not conditions:
continue

for condition in conditions:
if condition.status != "True":
continue

if condition.type == "Complete":
print(f"Job {job_name} completed successfully.")
return

if condition.type == "Failed":
print(f"Job {job_name} failed.")
return
finally:
w.stop()

print(
f"Timeout or job {job_name} did not reach a complete/failed state within the specified timeout."
)


def main():
namespace = os.environ["NAMESPACE"]

for case in TEST_CASES:
job_name = f"memtier-benchmark-{case.name}"

print(f"Running case {job_name}")
v1.create_namespaced_job(
namespace=namespace,
body=models.V1Job(
metadata={"name": f"memtier-benchmark-{case.name}"},
spec=models.V1JobSpec(
backoff_limit=0,
template=models.V1JobTemplateSpec(
spec={
"restartPolicy": "Never",
"containers": [
models.V1Container(
name="memtier",
image="redislabs/memtier_benchmark:latest",
args=[
"memtier_benchmark --pipeline=30 --key-maximum=10000 -c 10 -t 2 --requests=500000 --expiry-range=10-100 --reconnect-interval=10000 --distinct-client-seed --hide-histogram -s dragonfly-sample"
],
command=[
# This is important! without it memtier cannot DIG the dragonfly SVC domain
"sh",
"-c",
],
resources={
"requests": {"cpu": "2", "memory": "500Mi"},
"limits": {"cpu": "2", "memory": "500Mi"},
},
)
],
}
),
),
),
)
wait_for_job_completion(namespace, job_name, case.timeout)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions tools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ requests==2.28.1
aiocsv==1.2.3
aiofiles==22.1.0
numpy==1.24.1
kubernetes==26.1.0
attrs==22.2.0
Loading