Skip to content

Commit 0d2b2c5

Browse files
[add] Further improved the remote profiler daemon (#235)
1 parent 662a393 commit 0d2b2c5

File tree

6 files changed

+122
-74
lines changed

6 files changed

+122
-74
lines changed

poetry.lock

Lines changed: 39 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisbench-admin"
3-
version = "0.5.12"
3+
version = "0.5.13"
44
description = "Redis benchmark run helper. A wrapper around Redis and Redis Modules benchmark tools ( ftsb_redisearch, memtier_benchmark, redis-benchmark, aibench, etc... )."
55
authors = ["filipecosta90 <[email protected]>","Redis Performance Group <[email protected]>"]
66
readme = "README.md"
@@ -27,7 +27,7 @@ python_terraform = "^0.10.1"
2727
GitPython = "^3.1.12"
2828
PyYAML = "^5.4.0"
2929
wget = "^3.2"
30-
pytablewriter = "^0.60.0"
30+
pytablewriter = {extras = ["html"], version = "^0.64.1"}
3131
sshtunnel = "^0.4.0"
3232
pyWorkFlow = "^0.0.2"
3333
Flask = "^2.0.1"

redisbench_admin/profilers/daemon.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66

77
# !/usr/bin/env python3
88
import logging
9-
from threading import Thread
109

1110
from flask import Flask, request
1211
import daemonize
13-
from time import sleep
1412
import json
1513
import sys
1614
import os
@@ -41,10 +39,13 @@ def __init__(self):
4139

4240
def main(self):
4341
app = Flask(__name__)
44-
app.debug = False
45-
app.use_reloader = True
42+
app.use_reloader = False
4643
self.perf = Perf()
44+
self.set_app_loggers(app)
45+
self.create_app_endpoints(app)
46+
app.run(debug=False, host="0.0.0.0")
4747

48+
def set_app_loggers(self, app):
4849
print("Writting log to {}".format(LOGNAME))
4950
handler = logging.handlers.RotatingFileHandler(LOGNAME, maxBytes=1024 * 1024)
5051
logging.getLogger("werkzeug").setLevel(logging.DEBUG)
@@ -53,10 +54,15 @@ def main(self):
5354
app.logger.addHandler(handler)
5455
self.perf.set_logger(app.logger)
5556

57+
def create_app_endpoints(self, app):
5658
@app.before_first_request
5759
def before_first_request():
5860
app.logger.setLevel(logging.INFO)
5961

62+
@app.get("/ping")
63+
def ping():
64+
return json.dumps({"result": True})
65+
6066
@app.route("/profiler/<profiler_name>/start/<pid>", methods=["POST"])
6167
def profile_start(profiler_name, pid):
6268
setup_process_number = 1
@@ -146,6 +152,7 @@ def profile_status(profiler_name, pid):
146152
def profile_stop(profiler_name, pid):
147153
profile_res = self.perf.stop_profile()
148154
profilers_artifacts_matrix = []
155+
bucket_location = "us-east-2"
149156
primary_id = 1
150157
total_primaries = 1
151158
if profile_res is True:
@@ -196,6 +203,7 @@ def profile_stop(profiler_name, pid):
196203
[profile_artifact],
197204
S3_BUCKET_NAME,
198205
s3_bucket_path,
206+
bucket_location,
199207
)
200208
s3_link = list(url_map.values())[0]
201209
profilers_artifacts_matrix.append(
@@ -215,31 +223,26 @@ def profile_stop(profiler_name, pid):
215223
self.perf = Perf()
216224
return json.dumps(status_dict)
217225

218-
Thread(target=app.run).start()
219-
220-
self.loop()
221-
222-
def loop(self):
223-
while True:
224-
sleep(1)
225-
226226

227227
d = PerfDaemon()
228228

229229

230230
def main():
231-
global stop
232231
global d
233232

234-
def start():
233+
def start(foreground=False):
235234
current_path = os.path.abspath(os.getcwd())
236235
print(
237236
"Starting perfdaemon. PID file {}. Daemon workdir: {}".format(
238237
PID_FILE, current_path
239238
)
240239
)
241240
daemonize.Daemonize(
242-
app="perfdaemon", pid=PID_FILE, action=d.main, chdir=current_path
241+
app="perfdaemon",
242+
pid=PID_FILE,
243+
action=d.main,
244+
chdir=current_path,
245+
foreground=foreground,
243246
).start()
244247

245248
def stop():
@@ -250,7 +253,7 @@ def stop():
250253
os.system("kill -9 %s" % pid)
251254

252255
def foreground():
253-
d.main()
256+
start(True)
254257

255258
def usage():
256259
print("usage: start|stop|restart|foreground")

redisbench_admin/profilers/perf_daemon_caller.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def start_profile(self, pid, output="", frequency=99):
6262
"dso": self.dso,
6363
"test_name": self.test_name,
6464
"setup_name": self.setup_name,
65+
"github_actor": self.github_actor,
66+
"github_branch": self.github_branch,
67+
"github_repo_name": self.github_repo_name,
68+
"github_org_name": self.github_org_name,
69+
"github_sha": self.github_sha,
6570
}
6671
url = "http://{}/profiler/perf/start/{}?frequency={}".format(
6772
self.remote_endpoint, pid, frequency

0 commit comments

Comments
 (0)