-
Notifications
You must be signed in to change notification settings - Fork 527
Add performance test #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
davidbrochart
wants to merge
13
commits into
voila-dashboards:main
Choose a base branch
from
davidbrochart:performance_test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add performance test #542
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2aa6bdb
Add performance test
davidbrochart b979ea3
Replace wget with curl for OSX compatibility
davidbrochart bdf25c5
Let more time for Voila to start (OSX issue)
davidbrochart 6ccc8dd
Allow more time on OSX, disable silent curl
davidbrochart 872be86
Replace localhost with 127.0.0.1
davidbrochart 6a8dfec
100% margin on the mean time per cell
davidbrochart 4b72d70
200% margin on the mean time per cell
davidbrochart 962a325
Add docstrings, use nbformat for notebook generation
davidbrochart 7195b0b
Fix typos
davidbrochart 9902551
Timeout should be set according to exceed_pct
davidbrochart 6fe5684
Remove unused variable
davidbrochart e93fc63
Timeout doesn't take into account kernel launch time (wait for them t…
davidbrochart 091504d
Max execution time is now an absolute value rather than a percentage
davidbrochart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import subprocess | ||
| import time | ||
| import os | ||
| import shutil | ||
| import sys | ||
|
|
||
|
|
||
| def get_cell(seconds): | ||
| cell = ', { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], ' \ | ||
| '"source": [ "time.sleep(' + str(seconds) + ')\\n", "t1 = time.time()\\n", "log += ' \ | ||
| 'str(t1 - t0) + \'\\\\n\'\\n", "t0 = t1" ] }' | ||
| return cell | ||
|
|
||
|
|
||
| def get_ipynb(cell_nb, sleep_per_cell, result_dir): | ||
| ipynb = '{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs"' \ | ||
| ': [], "source": [ "import uuid\\n", "import time\\n", "fname = str(uuid.uuid4()) + \'' \ | ||
| '.log\'\\n", "log = \'\'\\n", "t0 = time.time()" ] }' | ||
| for i in range(cell_nb): | ||
| cell = get_cell(sleep_per_cell) | ||
| ipynb += cell | ||
| ipynb += ', { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], ' \ | ||
| '"source": [ "with open(\'' + result_dir + '/\' + fname, \'w\') as f:\\n", " ' \ | ||
| 'f.write(log)" ] }' | ||
| ipynb += ' ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", ' \ | ||
| '"name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", ' \ | ||
| '"version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python"' \ | ||
| ', "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.1" } }' \ | ||
| ', "nbformat": 4, "nbformat_minor": 4 }' | ||
| return ipynb | ||
|
|
||
|
|
||
| def test_performance(): | ||
| sleep_per_cell = 0.1 # each cell sleeps for that amount of seconds | ||
| cell_nb = 100 # each notebook consists of so many cells | ||
| client_nb = 10 # number of clients (kernels) launched in parallel | ||
| ipynb_path = 'tests/notebooks/sleep.ipynb' # generated notebook, results are stored in the directory without ".ipynb" | ||
|
|
||
| ipynb_dname, ipynb_fname = os.path.split(ipynb_path) | ||
| os.chdir(ipynb_dname) | ||
| result_dir = ipynb_fname[:-6] | ||
|
|
||
| if os.path.exists(result_dir): | ||
| shutil.rmtree(result_dir) | ||
| os.makedirs(result_dir) | ||
|
|
||
| ipynb = get_ipynb(cell_nb, sleep_per_cell, result_dir) | ||
|
|
||
| # generate notebook | ||
| with open(ipynb_fname, 'w') as f: | ||
| f.write(ipynb) | ||
|
|
||
| # launch voila | ||
| voila = subprocess.Popen(('voila --no-browser ' + ipynb_fname).split()) | ||
| time.sleep(1) | ||
|
|
||
| # launch clients | ||
| clients = [subprocess.Popen('curl http://localhost:8866 -o /dev/null'.split()) for i in range(client_nb)] | ||
|
|
||
| # wait for all notebooks to execute | ||
| t0 = time.time() | ||
| done = False | ||
| timeout = False | ||
| i = 0 | ||
| exec_time = cell_nb * sleep_per_cell # notebook execution time | ||
| launch_time = client_nb * 0.5 # kernel takes about 0.5s to launch | ||
| # min_time = launch_time + exec_time # theoretical time for all notebooks to execute | ||
| timeout_time = launch_time + 2 * exec_time # timeout allows slow machines to finish | ||
| while not done: | ||
| time.sleep(1) | ||
| done = True | ||
| i += 1 | ||
| # print(i, '/', min_time) | ||
| for client in clients: | ||
| if client.poll() is None: | ||
| done = False | ||
| if not done: | ||
| if time.time() - t0 > timeout_time: | ||
| done = True | ||
| timeout = True | ||
|
|
||
| # stop voila and all clients | ||
| voila.kill() | ||
| [client.kill() for client in clients] | ||
|
|
||
| if timeout: | ||
| raise TimeoutError | ||
|
|
||
| # analyze data | ||
| fnames = os.listdir(result_dir) | ||
| data = [] | ||
| for fname in fnames: | ||
| with open(result_dir + '/' + fname) as f: | ||
| data += [float(d) for d in f.read().split()] | ||
|
|
||
| meantime_per_cell = sum(data) / len(data) | ||
| exceed_pct = 50 # allowing for time budget exceedance (%) | ||
| maxtime_per_cell = sleep_per_cell * (exceed_pct / 100 + 1) | ||
| if meantime_per_cell > maxtime_per_cell: | ||
| print('Mean time per cell', meantime_per_cell, '>', sleep_per_cell, '(with', exceed_pct, '% margin)') | ||
| sys.exit(1) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.