summaryrefslogtreecommitdiff
path: root/scripts/scalability/test_controller/server
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2017-10-29 14:28:12 -0200
committerdrebs <drebs@riseup.net>2017-11-02 09:36:31 -0200
commita7f93cec7999de04614d7adaf91c4348a3313e2e (patch)
treeea7e089f0f3d7baec50bc34f0cf39bbedefcd8fd /scripts/scalability/test_controller/server
parent21584bc33fdc672a0f59436ba5d66f66439d6366 (diff)
[benchmarks] add some orchestration to scalability tests
Diffstat (limited to 'scripts/scalability/test_controller/server')
-rw-r--r--scripts/scalability/test_controller/server/server.tac30
-rwxr-xr-xscripts/scalability/test_controller/server/user_dbs.py23
-rw-r--r--scripts/scalability/test_controller/server/utils.py22
3 files changed, 60 insertions, 15 deletions
diff --git a/scripts/scalability/test_controller/server/server.tac b/scripts/scalability/test_controller/server/server.tac
index d5176319..72b1df10 100644
--- a/scripts/scalability/test_controller/server/server.tac
+++ b/scripts/scalability/test_controller/server/server.tac
@@ -49,6 +49,7 @@ from twisted.logger import Logger
from test_controller.server.user_dbs import ensure_dbs
from test_controller.server.blobs import create_blobs
from test_controller.server.blobs import delete_blobs
+from test_controller.server.utils import get_soledad_server_pid
DEFAULT_HTTP_PORT = 7001
@@ -62,6 +63,9 @@ logger = Logger(__name__)
#
class ResourceWatcher(object):
+ """
+ A generic system resource watcher. Real watchers inherit from this class.
+ """
def __init__(self, pid):
logger.info('%s started for process with PID %d'
@@ -95,6 +99,9 @@ class ResourceWatcher(object):
class CpuWatcher(ResourceWatcher):
+ """
+ A watcher that trackes cpu usage of a process.
+ """
interval = 1
@@ -118,6 +125,9 @@ def _std(l):
class MemoryWatcher(ResourceWatcher):
+ """
+ A watcher that tracks the memory usage of a process.
+ """
interval = 0.1
@@ -161,7 +171,9 @@ class InvalidPidError(Exception):
class MonitorResource(resource.Resource):
"""
- A generic resource-monitor web resource.
+ A generic web resource to monitor system resources. Which system resource
+ it allows monitoring depends on the watcher class passed to the
+ constructor.
"""
isLeaf = 1
@@ -173,7 +185,7 @@ class MonitorResource(resource.Resource):
def _get_pid(self, request):
if 'pid' not in request.args:
- raise MissingPidError()
+ return get_soledad_server_pid()
pid = request.args['pid'].pop()
if not pid.isdigit():
raise InvalidPidError(pid)
@@ -206,7 +218,11 @@ class MonitorResource(resource.Resource):
self.watcher.stop()
-class SetupResource(resource.Resource):
+class UsersResource(resource.Resource):
+ """
+ Allow controlling the creation of server-side user databases and access
+ tokens.
+ """
def render_POST(self, request):
create = request.args.get('create') or [1000]
@@ -228,6 +244,9 @@ class SetupResource(resource.Resource):
class BlobsResource(resource.Resource):
+ """
+ Allow controlling the creation and deletion of server-side blobs.
+ """
def render_POST(self, request):
action = (request.args.get('action') or ['create']).pop()
@@ -255,12 +274,15 @@ class BlobsResource(resource.Resource):
class Root(resource.Resource):
+ """
+ The root resource that gives access to all others.
+ """
def __init__(self):
resource.Resource.__init__(self)
self.putChild('mem', MonitorResource(MemoryWatcher))
self.putChild('cpu', MonitorResource(CpuWatcher))
- self.putChild('setup', SetupResource())
+ self.putChild('users', UsersResource())
self.putChild('blobs', BlobsResource())
diff --git a/scripts/scalability/test_controller/server/user_dbs.py b/scripts/scalability/test_controller/server/user_dbs.py
index 70fbd96d..c1012cc0 100755
--- a/scripts/scalability/test_controller/server/user_dbs.py
+++ b/scripts/scalability/test_controller/server/user_dbs.py
@@ -15,6 +15,7 @@ from urlparse import urljoin
from twisted.internet import reactor, defer
from twisted.logger import Logger
+
COUCH_URL = "http://127.0.0.1:5984"
CREATE = 1000
@@ -56,10 +57,10 @@ def _req(method, *args, **kwargs):
@defer.inlineCallbacks
-def delete_dbs(dbs):
+def delete_dbs(couch_url, dbs):
deferreds = []
for db in dbs:
- d = semaphore.run(_req, 'delete', urljoin(COUCH_URL, db))
+ d = semaphore.run(_req, 'delete', urljoin(couch_url, db))
logfun = partial(_log, 'table', db, 'deleted')
d.addCallback(logfun)
deferreds.append(d)
@@ -69,10 +70,10 @@ def delete_dbs(dbs):
@defer.inlineCallbacks
-def create_dbs(dbs):
+def create_dbs(couch_url, dbs):
deferreds = []
for db in dbs:
- d = semaphore.run(_req, 'put', urljoin(COUCH_URL, db))
+ d = semaphore.run(_req, 'put', urljoin(couch_url, db))
logfun = partial(_log, 'table', db, 'created')
d.addCallback(logfun)
deferreds.append(d)
@@ -98,13 +99,13 @@ def _create_token(res, url, user_id):
defer.returnValue(res)
-def create_tokens(create):
+def create_tokens(couch_url, create):
deferreds = []
tokens_db = _get_tokens_db_name()
for i in xrange(create):
user_id = str(i)
token = sha512('%s-token' % user_id).hexdigest()
- url = '/'.join([COUCH_URL, tokens_db, token])
+ url = '/'.join([couch_url, tokens_db, token])
d = semaphore.run(_req, 'get', url)
d.addCallback(_create_token, url, user_id)
logfun = partial(_log, 'token', user_id, 'created')
@@ -115,15 +116,15 @@ def create_tokens(create):
@defer.inlineCallbacks
def ensure_dbs(couch_url=COUCH_URL, create=CREATE):
- dbs = get_db_names(create)
- yield delete_dbs(dbs)
- yield create_dbs(dbs)
- yield create_tokens(create)
+ # dbs = get_db_names(create)
+ # yield delete_dbs(couch_url, dbs)
+ # yield create_dbs(couch_url, dbs)
+ yield create_tokens(couch_url, create)
@defer.inlineCallbacks
def main(couch_url, create):
- yield ensure_dbs(couch_url, create)
+ yield ensure_dbs(couch_url=couch_url, create=create)
reactor.stop()
diff --git a/scripts/scalability/test_controller/server/utils.py b/scripts/scalability/test_controller/server/utils.py
new file mode 100644
index 00000000..a8274490
--- /dev/null
+++ b/scripts/scalability/test_controller/server/utils.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+
+from subprocess import check_output
+from psutil import Process
+
+args = set([
+ '/usr/bin/twistd',
+ '--python=/usr/lib/python2.7/dist-packages/leap/soledad/server/server.tac',
+])
+
+
+def get_soledad_server_pid():
+ output = check_output(['pidof', 'python'])
+ for pid in output.split():
+ proc = Process(int(pid))
+ cmdline = proc.cmdline()
+ if args.issubset(set(cmdline)):
+ return int(pid)
+
+
+if __name__ == '__main__':
+ print get_soledad_server_pid()