-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment.py
58 lines (37 loc) · 1.77 KB
/
experiment.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
"""
Module containing various webapps that are used in the experiments.
The apps are expected to be run with `gunicorn`. Configuration file in `./gunicorn.conf.py`.
It is also expected that the apps would be run on a 'production' level.
Usage:
* If Faasm processing should be disabled.
* `gunicorn 'experiment:<create-func-name>()'`
* If Faasm processing should be enabled.
* `gunicorn 'experiment:<create-func-name>(faasm=True)'`
"""
import logging
from flask import Flask
from lib.faasm import upload_cpython_runtime
from lib.flask import process_flask_app
from webapp import echo_app, pyperformance_app, simple_app
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
def _create_app(app: Flask, use_faasm: bool = False, use_lib: bool = False) -> Flask:
"""Internal function for processing the given Flask `app`."""
logger.info("Using Faasm!" if use_faasm else "Not using Faasm!")
# Process the app if Faasm is used.
if use_faasm:
logger.info("Uploading CPython runtime...")
upload_cpython_runtime()
logger.info("Finished uploading CPython runtime.")
logger.info(f"Processing Flask app {app.name}...")
process_flask_app(app, use_lib)
logger.info("Finished processing Flask app.")
logger.info("Finished processing the app.")
return app
# Helper variables for processing various apps with default configurations.
def create_echo_app(faasm: bool = False) -> Flask:
return _create_app(echo_app, use_faasm=faasm, use_lib=False)
def create_simple_app(faasm: bool = False) -> Flask:
return _create_app(simple_app, use_faasm=faasm, use_lib=False)
def create_pyperformance_app(faasm: bool = False) -> Flask:
return _create_app(pyperformance_app, use_faasm=faasm, use_lib=True)