Skip to content
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

Update and extend PAPI support #213

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion config/systems.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"images": [
"run",
"build"
"build",
"run-papi"
],
"username": "docker_user",
"deployment": {
Expand Down
2 changes: 0 additions & 2 deletions dockerfiles/local/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ if [ ! -z "$CMD" ]; then
gosu ${USER} $CMD
fi

chown -R ${USER}:${USER} /sebs/
echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/dont-prompt-$USER-for-password
usermod -aG sudo ${USER}

exec gosu ${USER} "$@"

1 change: 0 additions & 1 deletion dockerfiles/local/python/Dockerfile.run
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ COPY dockerfiles/local/python/*.py /sebs/
COPY dockerfiles/local/python/run_server.sh /sebs/
COPY dockerfiles/local/python/timeit.sh /sebs/
COPY dockerfiles/local/python/runners.json /sebs/
ADD third-party/pypapi/pypapi /sebs/pypapi
ENV PYTHONPATH=/sebs/.python_packages/lib/site-packages:$PYTHONPATH

COPY dockerfiles/local/entrypoint.sh /sebs/entrypoint.sh
Expand Down
37 changes: 37 additions & 0 deletions dockerfiles/local/python/Dockerfile.run-papi
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

RUN deps=''\
&& apt-get update\
# for route and sudo
&& apt-get install --no-install-recommends -y make gcc libc6-dev\
&& pip3 install cffi

ADD third-party/pypapi /pypapi
RUN cd /pypapi && python setup.py build && python pypapi/papi_build.py

FROM ${BASE_IMAGE}

COPY --from=0 /pypapi/ /pypapi/

RUN deps=''\
&& apt-get update\
# for route and sudo
&& apt-get install --no-install-recommends -y curl gosu net-tools sudo ${deps}\
&& apt-get purge -y --auto-remove ${deps}\
&& pip3 install cffi minio bottle

RUN mkdir -p /sebs
COPY dockerfiles/local/run.sh /sebs/
COPY dockerfiles/local/*.py /sebs/
COPY dockerfiles/local/python/*.py /sebs/
COPY dockerfiles/local/python/run_server.sh /sebs/
COPY dockerfiles/local/python/timeit.sh /sebs/
COPY dockerfiles/local/python/runners.json /sebs/
ENV PYTHONPATH=/pypapi:/sebs/.python_packages/lib/site-packages:$PYTHONPATH

COPY dockerfiles/local/entrypoint.sh /sebs/entrypoint.sh
RUN chmod +x /sebs/entrypoint.sh
RUN chmod +x /sebs/run.sh

ENTRYPOINT ["/sebs/entrypoint.sh"]
8 changes: 7 additions & 1 deletion sebs.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ def local():
@click.argument("benchmark-input-size", type=click.Choice(["test", "small", "large"]))
@click.argument("output", type=str)
@click.option("--deployments", default=1, type=int, help="Number of deployed containers.")
@click.option(
"--with-papi/--no-with-papi",
default=True,
help="Start container enabled with PAPI counters.",
)
@click.option("--storage-configuration", type=str, help="JSON configuration of deployed storage.")
@click.option("--measure-interval", type=int, default=-1,
help="Interval duration between memory measurements in ms.")
Expand All @@ -417,7 +422,7 @@ def local():
help="Remove containers after stopping.",
)
@simplified_common_params
def start(benchmark, benchmark_input_size, output, deployments, storage_configuration,
def start(benchmark, benchmark_input_size, output, deployments, with_papi, storage_configuration,
measure_interval, remove_containers, **kwargs):
"""
Start a given number of function instances and a storage instance.
Expand All @@ -429,6 +434,7 @@ def start(benchmark, benchmark_input_size, output, deployments, storage_configur
)
deployment_client = cast(sebs.local.Local, deployment_client)
deployment_client.remove_containers = remove_containers
deployment_client.with_papi = with_papi
result = sebs.local.Deployment()
result.measurement_file = deployment_client.start_measurements(measure_interval)

Expand Down
25 changes: 18 additions & 7 deletions sebs/local/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def remove_containers(self) -> bool:
def remove_containers(self, val: bool):
self._remove_containers = val

@property
def with_papi(self) -> bool:
return self._with_papi

@with_papi.setter
def with_papi(self, val: bool):
self._with_papi = val

@property
def measure_interval(self) -> int:
return self._measure_interval
Expand All @@ -71,6 +79,7 @@ def __init__(
self.logging_handlers = logger_handlers
self._config = config
self._remove_containers = True
self._with_papi = False
self._memory_measurement_path: Optional[str] = None
# disable external measurements
self._measure_interval = -1
Expand Down Expand Up @@ -157,8 +166,9 @@ def package_code(

def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunction":

container_name = "{}:run.local.{}.{}".format(
container_name = "{}:{}.local.{}.{}".format(
self._system_config.docker_repository(),
"run-papi" if self._with_papi else "run",
code_package.language_name,
code_package.language_version,
)
Expand All @@ -174,6 +184,12 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc
self.name(), code_package.language_name
),
}

options = {}
# Enable PAPI counters
if self.with_papi:
options["cap_add"] = ["PERFMON"]

container = self._docker_client.containers.run(
image=container_name,
command=f"/bin/bash /sebs/run_server.sh {self.DEFAULT_PORT}",
Expand All @@ -182,18 +198,13 @@ def create_function(self, code_package: Benchmark, func_name: str) -> "LocalFunc
# FIXME: make CPUs configurable
# FIXME: configure memory
# FIXME: configure timeout
# cpuset_cpus=cpuset,
# required to access perf counters
# alternative: use custom seccomp profile
privileged=True,
security_opt=["seccomp:unconfined"],
network_mode="bridge",
# somehow removal of containers prevents checkpointing from working?
remove=self.remove_containers,
stdout=True,
stderr=True,
detach=True,
# tty=True,
**options,
)

pid: Optional[int] = None
Expand Down
2 changes: 1 addition & 1 deletion tools/build_docker_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
parser.add_argument(
"--deployment", default=None, choices=["local", "aws", "azure", "gcp"], action="store"
)
parser.add_argument("--type", default=None, choices=["build", "run", "manage"], action="store")
parser.add_argument("--type", default=None, choices=["build", "run", "run-papi", "manage"], action="store")
parser.add_argument("--language", default=None, choices=["python", "nodejs"], action="store")
parser.add_argument("--language-version", default=None, type=str, action="store")
args = parser.parse_args()
Expand Down