forked from mhausenblas/dromedar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qsf.py
executable file
·76 lines (58 loc) · 2.4 KB
/
qsf.py
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
#!/usr/bin/env python
"""
Launches as many Drillbits as specified in relation to dataset size under query.
Assumes that Drill is installed and Mesos + Marathon are deployed and running.
Usage:
./qsf.py $MARATHON_URL $[FACTOR=100]
Example:
./qsf.py http://localhost:8080 10 # launch QFS == 1:10, that is 1 Drillbit per 10MB
@author: Michael Hausenblas, http://mhausenblas.info/#i
@since: 2015-04-06
@status: init
"""
import logging
import os
import sys
import time
import SimpleHTTPServer
import SocketServer
from marathon import MarathonClient
from marathon.models import MarathonApp
################################################################################
# Defaults
#
DEBUG = True
if DEBUG:
FORMAT = '%(asctime)-0s %(levelname)s %(message)s [at line %(lineno)d]'
logging.basicConfig(level=logging.DEBUG, format=FORMAT, datefmt='%Y-%m-%dT%I:%M:%S')
else:
FORMAT = '%(asctime)-0s %(message)s'
logging.basicConfig(level=logging.INFO, format=FORMAT, datefmt='%Y-%m-%dT%I:%M:%S')
QSF_DEFAULT = 100 # 1 Drillbit per 100MB dataset size
QSF_PORT = 9876
def launch_drillbits(marathon_url, scale_factor):
logging.info('Launching Drillbits using %s and scale factor %d' %(marathon_url, int(scale_factor)))
# launch Drillbits via Marathon REST API
c = MarathonClient(marathon_url)
# c.create_app('dromedar-drill', MarathonApp(cmd='dromedar-master/launch-drillbit.sh', uris=['https://github.com/mhausenblas/dromedar/archive/master.zip'], mem=400, cpus=1))
c.create_app('dromedar-drill', MarathonApp(cmd='sudo /opt/drill/apache-drill-0.8.0/bin/drillbit.sh start', mem=400, cpus=1))
print('Drillbits are deployed: DATASETSIZE, NUM_DRILLBITS')
httpd = SocketServer.TCPServer(("", QSF_PORT), SimpleHTTPServer.SimpleHTTPRequestHandler)
logging.info('Now listening to change requests on port %d' %(QSF_PORT))
httpd.serve_forever()
################################################################################
# Main script
#
if __name__ == '__main__':
try:
marathon_url = sys.argv[1] # Marathon URL to use
try:
scale_factor = sys.argv[2]
except:
scale_factor = QSF_DEFAULT
# TODO: rewrite into HTTP-based long-running service, also: Marathon URL comes from dromedar main launch
launch_drillbits(marathon_url, scale_factor)
except Exception, e:
print(e)
print(__doc__)
sys.exit(2)