-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
89 lines (82 loc) · 2.36 KB
/
tasks.py
File metadata and controls
89 lines (82 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
from celery import Celery
import os
import subprocess
import redis
import csv
import time
import requests
broker_url = os.getenv("BROKER_URL")
app = Celery("hello", broker=broker_url)
@app.task
def redis_benchmark(port, flavour, req=1000000):
r = redis.Redis(host="127.0.0.1", port=port, db=0)
r.flushall()
gts = []
info = {}
try:
info = r.info()
except:
return False
process = subprocess.Popen(
[
"redis-benchmark",
"-q",
"-n",
str(req),
"--csv",
"-d",
"1000",
"--threads",
"2",
"-p",
str(port),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()
ustime = str(int(time.time_ns() / 1000))
csv_reader = csv.reader(stdout.decode("ascii").splitlines(), delimiter=",")
line_count = 0
definitions = {}
for row in csv_reader:
if line_count == 0:
definition = row
line_count += 1
else:
j = 1
while j < len(row):
line = (
"{}// {}-{}(redis_version={},os={},cc_version={},redis_build_id={},tcp_port={},flavour={},req={}) {}".format(
ustime,
row[0].split(" ")[0].lower(),
definition[j].split(" ")[0].split("_")[0],
info["redis_version"],
info["os"].replace(" ", "_"),
info["gcc_version"],
info["redis_build_id"],
info["tcp_port"],
flavour,
req,
row[j],
)
.replace("(", "{")
.replace(")", "}")
)
gts.append(line)
j += 1
line_count += 1
return send_warp10("\n".join(gts))
def send_warp10(gts):
url = os.getenv("WARP10_URL")
headers = {
"X-Warp10-Token": os.getenv("WARP10_WRITE_TOKEN"),
"Content-Type": "text/plain",
}
response = requests.request("POST", url, headers=headers, data=gts)
if response.status_code == 200:
print("Success")
return True
print("Failed")
return False