Skip to content

Commit

Permalink
support python3 in ailab, also fixes some minor issues
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #279

Reviewed By: hl475

Differential Revision: D15196928

Pulled By: sf-wind

fbshipit-source-id: 633e27c8cee4531aa782fc3c7a3db0d66456fcae
  • Loading branch information
sf-wind authored and facebook-github-bot committed May 6, 2019
1 parent cdeb5f7 commit b674c39
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ ailab/*/migrations/*.py

# Django secret key
ailab/ailab/secret_key.py

ailab/static/
ailab/media/
16 changes: 12 additions & 4 deletions ailab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ apt-get install python-dev libmysqlclient-dev


- Install components for ailab:
- Python2
```
pip install MySQL-python
pip install django-tables2 "django<2" django-nvd3 django-widget-tweaks django-bootstrap3
```
- Python3 (On Mac, follow instructions in https://pypi.org/project/mysqlclient/ to fix `mysqlclient` package)
```
pip install mysqlclient
pip install django-tables2 django-nvd3 django-widget-tweaks django-bootstrap3
```
- In the current directory (ailab), run the following commands:
```
Expand Down Expand Up @@ -88,19 +94,21 @@ nginx
```
python manage.py collectstatic --clear
```
2. Start uWSGI from this directory in production setting
2. Start uWSGI from this directory in production setting.
Need to increase the buffer size since the URL may be quite long.
```
uwsgi --socket :8001 --module ailab.wsgi
uwsgi --socket :8001 --module ailab.wsgi -b 32768
```

Now, the server should be up and running, ready to receive requests.


## Start Lab
On server, inside `benchmarking` directory, run:
On server, inside `benchmarking` directory, run the following command to start an android lab:
```
python run_bench.py --lab --claimer_id <claimer_id> --server_addr <server_name> --remote_reporter "<server_name>/benchmark/store-result|oss"
python run_bench.py --lab --claimer_id <claimer_id> --server_addr <server_name> --remote_reporter "<server_name>/benchmark/store-result|oss" --platform android
```
The lab needs to be able to build android binary.

## Run Benchmark Remotely
On another machine, inside `benchmarking` directory, invoke the lab by running:
Expand Down
2 changes: 1 addition & 1 deletion ailab/benchmark/benchmark_result_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def store_result(data):
for log in logs:
store_single_entry(log)

return {"status": "success"}
return {"status": "success", "count": len(logs)}


def store_single_entry(log):
Expand Down
5 changes: 4 additions & 1 deletion ailab/benchmark/templates/result_visualization.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@


<div class="container-fluid">
<nav class="navbar navbar-default">
<a class="navbar-brand" href="https://github.com/facebook/FAI-PEP">FAI-PEP</a>
</nav>
<div class="row">
<div class="col-md-2">
<ul class="nav nav-tabs" id="configTab" role="tablist">
Expand Down Expand Up @@ -106,7 +109,7 @@ <h4 style="margin-top: 0">Graph Configuration</h4>
<div id="builder"></div>
</div>

<div class="col-md-8">
<div class="col-md-10">
<div id='graph-view' class="panel panel-default">
{% include 'graph_view.html' %}
</div>
Expand Down
14 changes: 7 additions & 7 deletions ailab/benchmark/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from django.views.decorators.csrf import csrf_exempt
from django_tables2 import RequestConfig

import db_controller
import benchmark_result_controller
from result_table import ResultTable
from .db_controller import get_payload
from .benchmark_result_controller import store_result
from .result_table import ResultTable
from .models import BenchmarkResult

import visualize_utils as utils
from .visualize_utils import construct_q


PLOTABLE_COL_SET = {
Expand All @@ -37,15 +37,15 @@
@csrf_exempt
def handle_request(request):
data = request.POST.copy()
results = db_controller.get_payload(data)
results = get_payload(data)

return JsonResponse(results)


@csrf_exempt
def store_benchmark_result(request):
data = json.loads(request.body)
results = benchmark_result_controller.store_result(data)
results = store_result(data)

return JsonResponse(results)

Expand All @@ -69,7 +69,7 @@ def visualize(request):
filters = {} if request.GET.get('filters') is None \
else json.loads(request.GET.get('filters'))
if len(filters) != 0 and filters['valid']:
result_q = utils.construct_q(filters)
result_q = construct_q(filters)
qs = BenchmarkResult.objects.filter(result_q)
else:
qs = BenchmarkResult.objects.all()
Expand Down
4 changes: 2 additions & 2 deletions benchmarking/bridge/upload_download_files_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, args):
def upload(self, **kwargs):
path = kwargs['file']
if self.server_addr:
storage_addr = self.server_addr + "upload/"
storage_addr = self.server_addr + "/upload/"
getLogger().info("Uploading {} to {}".format(path, storage_addr))
filename = os.path.basename(path)

Expand All @@ -27,7 +27,7 @@ def upload(self, **kwargs):

url = ''
if result_json['status'] == 'success':
url = self.server_addr + result_json['path']
url = self.server_addr + "/" + result_json['path']
getLogger().info("File has been uploaded to {}".format(url))
return url

Expand Down
9 changes: 7 additions & 2 deletions benchmarking/remote/django_url_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class DjangoURLPrinter(URLPrinterBase):
def __init__(self, args):
self.args = args
self.db_url = self.args.server_addr + DJANGO_SUB_URL
self.db_url = self.args.server_addr + "/" + DJANGO_SUB_URL

def getColumnSelParams(self):
col_sel_params = []
Expand Down Expand Up @@ -87,7 +87,12 @@ def getDjangoParams(self, user_identifier):
def printURL(self, dataset, user_identifier, benchmarks):
params = self.getDjangoParams(user_identifier)

param_string = urllib.urlencode(params)
try:
# pytyon 2
param_string = urllib.urlencode(params)
except Exception:
# python 3
param_string = urllib.parse.urlencode(params)

url = (
self.db_url + "?{}"
Expand Down
3 changes: 3 additions & 0 deletions benchmarking/run_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def _saveDefaultArgs(self, new_args):

def _askArgsFromUser(self, args, new_args):
args.update(new_args)
if "--server_addr" in args and "--remote_reporter" not in args:
args["--remote_reporter"] = args["--server_addr"] + "/benchmark/store-result|oss"
self._inputOneRequiredArg(
"Please enter the directory the framework repo resides",
"--repo_dir", args)
Expand Down Expand Up @@ -149,6 +151,7 @@ def _loadDefaultArgs(self):
'--timeout': 300,
'--logger_level': 'warning',
'--server_addr': "http://127.0.0.1:8000",
'--result_db': "django",
}
return args

Expand Down
2 changes: 2 additions & 0 deletions benchmarking/run_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import multiprocessing
import os
import stat
import sys
import tempfile
import threading
import time
Expand Down Expand Up @@ -502,6 +503,7 @@ def _downloadFiles(self, jobs_queue):
control_info = job["benchmarks"]["info"]["control"]
self._downloadBinaries(control_info)
except Exception:
getLogger().error("Unknown exception {}".format(sys.exc_info()[0]))
getLogger().error("File download failure")
return benchmark_files

Expand Down
4 changes: 2 additions & 2 deletions benchmarking/run_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def _buildProgram(self, tempdir):
allfiles = [program]
else:
allfiles = [os.path.join(filedir, f) for f in os.listdir(filedir)]

for fn in allfiles:
filename, _ = self.file_handler.uploadFile(fn, None, None, False)
getLogger().info("program: {}".format(filename))
Expand All @@ -183,7 +182,7 @@ def __init__(self, raw_args=None):
if not self.args.benchmark_db_entry:
assert self.args.server_addr is not None, \
"Either server_addr or benchmark_db_entry must be specified"
self.args.benchmark_db_entry = self.args.server_addr + "benchmark/"
self.args.benchmark_db_entry = self.args.server_addr + "/benchmark/"
self.db = DBDriver(self.args.benchmark_db,
self.args.app_id,
self.args.token,
Expand Down Expand Up @@ -302,6 +301,7 @@ def run(self):
self.db.submitBenchmarks(data, new_devices, user_identifier, user)
if self.args.async_submit:
return

self.url_printer.printURL(self.scuba_dataset,
user_identifier,
benchmarks)
Expand Down

0 comments on commit b674c39

Please sign in to comment.