From 4e87571816a8c994ff87c0619fd8c8b9fbcf232b Mon Sep 17 00:00:00 2001 From: Jerry Sun Date: Sun, 1 Sep 2024 01:06:57 -0400 Subject: [PATCH 1/3] finished markdown to html benchmark --- benchmarks/markdown_to_html/.gitignore | 1 + benchmarks/markdown_to_html/__init__.py | 0 benchmarks/markdown_to_html/app.py | 44 ++++++++++++++++++++ benchmarks/markdown_to_html/requirements.txt | 6 +++ benchmarks/markdown_to_html/src/.gitkeep | 0 benchmarks/markdown_to_html/src/__init__.py | 0 6 files changed, 51 insertions(+) create mode 100644 benchmarks/markdown_to_html/.gitignore create mode 100644 benchmarks/markdown_to_html/__init__.py create mode 100644 benchmarks/markdown_to_html/app.py create mode 100644 benchmarks/markdown_to_html/requirements.txt create mode 100644 benchmarks/markdown_to_html/src/.gitkeep create mode 100644 benchmarks/markdown_to_html/src/__init__.py diff --git a/benchmarks/markdown_to_html/.gitignore b/benchmarks/markdown_to_html/.gitignore new file mode 100644 index 00000000..004c0f21 --- /dev/null +++ b/benchmarks/markdown_to_html/.gitignore @@ -0,0 +1 @@ +.caribou/deployment-packages/ \ No newline at end of file diff --git a/benchmarks/markdown_to_html/__init__.py b/benchmarks/markdown_to_html/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/markdown_to_html/app.py b/benchmarks/markdown_to_html/app.py new file mode 100644 index 00000000..69770a4f --- /dev/null +++ b/benchmarks/markdown_to_html/app.py @@ -0,0 +1,44 @@ +from typing import Any +import markdown +import base64 +import boto3 +import json +from tempfile import TemporaryDirectory +from caribou.deployment.client import CaribouWorkflow + +s3_bucket_name = "caribou-markdown-to-html" +s3_bucket_region_name = "us-east-1" + +workflow = CaribouWorkflow(name="markdown_to_html", version="0.0.1") + +@workflow.serverless_function( + name="markdown_to_html", + entry_point=True, +) +def markdown_to_html(event: dict[str, Any]) -> dict[str, Any]: + + if isinstance(event, str): + event = json.loads(event) + + if "filename" in event: + filename = event["filename"] + else: + raise ValueError("No filename provided") + + s3 = boto3.client("s3", region_name=s3_bucket_region_name) + + with TemporaryDirectory() as tmp_dir: + s3.download_file(s3_bucket_name, filename, f"{tmp_dir}/{filename}") + + with open(f"{tmp_dir}/{filename}", "r") as f: + markdown_text = f.read() + + decoded_text = base64.b64decode(markdown_text).decode() + html_text = markdown.markdown(decoded_text) + + with open(f"{tmp_dir}/{filename}.html", "w") as f: + f.write(html_text) + + s3.upload_file(f"{tmp_dir}/{filename}.html", s3_bucket_name, f"output/{filename}.html") + + return {"status": 200} \ No newline at end of file diff --git a/benchmarks/markdown_to_html/requirements.txt b/benchmarks/markdown_to_html/requirements.txt new file mode 100644 index 00000000..5820f79a --- /dev/null +++ b/benchmarks/markdown_to_html/requirements.txt @@ -0,0 +1,6 @@ +markdown +boto3==1.35.3 + +pyyaml==6.0.2 + +pytz==2024.1 diff --git a/benchmarks/markdown_to_html/src/.gitkeep b/benchmarks/markdown_to_html/src/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/benchmarks/markdown_to_html/src/__init__.py b/benchmarks/markdown_to_html/src/__init__.py new file mode 100644 index 00000000..e69de29b From 080a497ca8d668af06579aa94ec10adb638256f9 Mon Sep 17 00:00:00 2001 From: Viktor Gsteiger Date: Tue, 17 Sep 2024 19:41:07 +0200 Subject: [PATCH 2/3] Update benchmarks/markdown_to_html/requirements.txt --- benchmarks/markdown_to_html/requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/benchmarks/markdown_to_html/requirements.txt b/benchmarks/markdown_to_html/requirements.txt index 5820f79a..482555ce 100644 --- a/benchmarks/markdown_to_html/requirements.txt +++ b/benchmarks/markdown_to_html/requirements.txt @@ -1,6 +1,4 @@ markdown boto3==1.35.3 - pyyaml==6.0.2 - pytz==2024.1 From acef608c68e8bbe35f79124f2d528ef225239dd5 Mon Sep 17 00:00:00 2001 From: Jerry Sun Date: Mon, 30 Sep 2024 22:01:05 -0400 Subject: [PATCH 3/3] added readme and license for benchmark --- .../markdown_to_html/.caribou/config.yml | 41 +++++++++++++++++++ .../markdown_to_html/.caribou/iam_policy.json | 31 ++++++++++++++ benchmarks/markdown_to_html/LICENSE | 21 ++++++++++ benchmarks/markdown_to_html/readme.md | 24 +++++++++++ 4 files changed, 117 insertions(+) create mode 100644 benchmarks/markdown_to_html/.caribou/config.yml create mode 100644 benchmarks/markdown_to_html/.caribou/iam_policy.json create mode 100644 benchmarks/markdown_to_html/LICENSE create mode 100644 benchmarks/markdown_to_html/readme.md diff --git a/benchmarks/markdown_to_html/.caribou/config.yml b/benchmarks/markdown_to_html/.caribou/config.yml new file mode 100644 index 00000000..953408d8 --- /dev/null +++ b/benchmarks/markdown_to_html/.caribou/config.yml @@ -0,0 +1,41 @@ +workflow_name: "markdown_to_html" +workflow_version: "0.0.1" +environment_variables: + - key: "ENV_VAR_1" + value: "value_1" +iam_policy_file: "iam_policy.json" +home_region: + provider: "aws" + region: "us-east-1" +estimated_invocations_per_month: 1000000 +constraints: + hard_resource_constraints: # None for none + cost: + type: "absolute" # Absolute value as 'absolute' (in USD) or Percentage from deployment at home regions as 'relative' (In fractions such as 1.1) + value: 100 + runtime: + type: "absolute" + value: 100 + carbon: + type: "absolute" + value: 100 + soft_resource_constraints: # None for none + cost: null + runtime: null + carbon: null + priority_order: + - cost + - runtime + - carbon +regions_and_providers: # Either the user specify only allowed regions (which will override everything else) + allowed_regions: + - provider: "aws" + region: "us-east-1" + disallowed_regions: + - provider: "aws" + region: "us-east-2" + providers: + aws: + config: + timeout: 60 + memory: 128 diff --git a/benchmarks/markdown_to_html/.caribou/iam_policy.json b/benchmarks/markdown_to_html/.caribou/iam_policy.json new file mode 100644 index 00000000..c5cb2748 --- /dev/null +++ b/benchmarks/markdown_to_html/.caribou/iam_policy.json @@ -0,0 +1,31 @@ +{ + "aws": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "logs:CreateLogGroup", + "logs:CreateLogStream", + "logs:PutLogEvents" + ], + "Resource": "arn:aws:logs:*:*:*", + "Effect": "Allow" + }, + { + "Action": ["sns:Publish"], + "Resource": "arn:aws:sns:*:*:*", + "Effect": "Allow" + }, + { + "Action": ["dynamodb:GetItem", "dynamodb:UpdateItem"], + "Resource": "arn:aws:dynamodb:*:*:*", + "Effect": "Allow" + }, + { + "Action": ["s3:GetObject", "s3:PutObject"], + "Resource": "arn:aws:s3:::*", + "Effect": "Allow" + } + ] + } +} diff --git a/benchmarks/markdown_to_html/LICENSE b/benchmarks/markdown_to_html/LICENSE new file mode 100644 index 00000000..be6e49a2 --- /dev/null +++ b/benchmarks/markdown_to_html/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Princeton University + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/benchmarks/markdown_to_html/readme.md b/benchmarks/markdown_to_html/readme.md new file mode 100644 index 00000000..c57a36d4 --- /dev/null +++ b/benchmarks/markdown_to_html/readme.md @@ -0,0 +1,24 @@ +# Markdown to HTML Benchmark + +Source for the adapted version used by us: https://github.com/PrincetonUniversity/faas-profiler/blob/master/functions/markdown-to-html/markdown2html.py + +The markdown_to_html benchmark converts a input Markdown file to HTML. It uses an S3 bucket for input and output file storage and is deployed using the Caribou framework. + +The benchmark requires access to an S3 bucket named `markdown_to_html` with the AWS Region set to `us-east-1`. Alternatively, users can specify a different bucket name and region by modifying `s3_bucket_name` and `s3_bucket_region_name` in the app.py file. + +There needs to be a markdown file in the bucket. + +You can deploy the benchmark with the following command while inside the poetry environment: +``` +caribou deploy +``` + +And then run the benchmark with the following command: +``` +caribou run markdown_to_html-version-number -a '{"filename": "file.md"}' +``` + +To remove the benchmark, you can use the following command: +``` +caribou remove markdown_to_html-version-number +``` \ No newline at end of file