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/.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/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/__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/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 diff --git a/benchmarks/markdown_to_html/requirements.txt b/benchmarks/markdown_to_html/requirements.txt new file mode 100644 index 00000000..482555ce --- /dev/null +++ b/benchmarks/markdown_to_html/requirements.txt @@ -0,0 +1,4 @@ +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