Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update benchmark script to use latest clkhash rest_client api
  • Loading branch information
hardbyte committed Feb 6, 2020
commit e2bed7dc9416ba39b4ff4e59e178bc7cb70823ea
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
anonlink==0.12.5
bitmath==1.3.1.2
celery==4.4.0
clkhash==0.15.0
clkhash==0.15.1
colorama==0.4.1 # required for structlog
connexion==1.4
Flask-Opentracing==0.2.0
Expand Down
31 changes: 16 additions & 15 deletions benchmarking/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import time
import os

from clkhash import rest_client
from clkhash.rest_client import RestClient
from pprint import pprint
from traceback import format_exc

Expand All @@ -41,6 +41,8 @@
logger = logging
logger.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)

rest_client = RestClient(os.getenv('SERVER'))


def load_experiments(filepath):

Expand Down Expand Up @@ -232,11 +234,11 @@ def compose_result(status, tt, experiment, sizes, threshold):
return result


def delete_resources(config, credentials, run):
def delete_resources(credentials, run):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great to see what key-value pairs might be in config in doc

try:
if run is not None and 'run_id' in run:
rest_client.run_delete(config['server'], credentials['project_id'], run['run_id'], credentials['result_token'])
rest_client.project_delete(config['server'], credentials['project_id'], credentials['result_token'])
rest_client.run_delete(credentials['project_id'], run['run_id'], credentials['result_token'])
rest_client.project_delete(credentials['project_id'], credentials['result_token'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it true that currently there is only server in config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there is lots of stuff in config all set around line 84. the change is because the new rest_client already knows the server address

except Exception as e:
logger.warning('Error while deleting resources... {}'.format(e))

Expand Down Expand Up @@ -299,8 +301,7 @@ def run_experiments(config):
"""
Run all the experiments specified in the configuration.
"""
server = config['server']
rest_client.server_get_status(server)
rest_client.server_get_status()

results = {'experiments': []}
for experiment in config['experiments']:
Expand All @@ -314,39 +315,39 @@ def run_experiments(config):
logger.info('running experiment: {}'.format(current_experiment))
if repetition != 1:
logger.info('\trepetition {} out of {}'.format(rep + 1, repetition))
result = run_single_experiment(server, config, threshold, sizes, current_experiment)
result = run_single_experiment(config, threshold, sizes, current_experiment)
results['experiments'].append(result)

return results


def run_single_experiment(server, config, threshold, sizes, experiment):
def run_single_experiment(config, threshold, sizes, experiment):
result = {}
credentials = {}
run = {}
logger.info("Starting time: {}".format(time.asctime()))
nb_parties = len(sizes)
try:
credentials = rest_client.project_create(server, config['schema'], 'groups',
credentials = rest_client.project_create(config['schema'], 'groups',
"benchy_{}".format(experiment), parties=nb_parties)
# upload clks
upload_binary_clks(config, sizes, credentials)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally, that should be done by the rest_client as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# create run
project_id = credentials['project_id']
result['project_id'] = project_id
run = rest_client.run_create(server, project_id, credentials['result_token'],
run = rest_client.run_create(project_id, credentials['result_token'],
threshold,
"{}_{}".format(experiment, threshold))
# wait for result
run_id = run['run_id']
result['run_id'] = run_id
logger.info(f'waiting for run {run_id} from the project {project_id} to finish')
status = rest_client.wait_for_run(server, project_id, run_id,
credentials['result_token'], timeout=config['timeout'])
status = rest_client.wait_for_run(project_id, run_id,
credentials['result_token'], timeout=config['timeout'], update_period=5)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will that lead to a new line in the logs every 5 seconds? what about those huge benchmarks? How big's the log file going to be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on the benchmark container side - we just wait until the whole thing is done (perhaps we should be outputting progress but that is another question).

On the server side we would log the request in both nginx and the flask app.

if status['state'] != 'completed':
raise RuntimeError('run did not finish!\n{}'.format(status))
logger.info('experiment successful. Evaluating results now...')
groups = rest_client.run_get_result_text(server, project_id, run_id, credentials['result_token'])
groups = rest_client.run_get_result_text(project_id, run_id, credentials['result_token'])
groups = json.loads(groups)['groups']
truth_groups = load_truth(config, sizes)
tt = score_accuracy(groups, truth_groups, nb_parties)
Expand All @@ -357,7 +358,7 @@ def run_single_experiment(server, config, threshold, sizes, experiment):
result.update({'name': experiment, 'status': 'ERROR', 'description': e_trace})
finally:
logger.info('cleaning up...')
delete_resources(config, credentials, run)
delete_resources(credentials, run)

logger.info("Ending time: {}".format(time.asctime()))
return result
Expand All @@ -383,7 +384,7 @@ def push_to_object_store(config):

def main():
config = read_config()
server_status = rest_client.server_get_status(config['server'])
server_status = rest_client.server_get_status()
version = requests.get(config['server'] + "/api/v1/version").json()
logger.info(server_status)
download_data(config)
Expand Down