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

markdown to html benchmark #312

Merged
merged 6 commits into from
Oct 1, 2024
Merged
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
41 changes: 41 additions & 0 deletions benchmarks/markdown_to_html/.caribou/config.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions benchmarks/markdown_to_html/.caribou/iam_policy.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
1 change: 1 addition & 0 deletions benchmarks/markdown_to_html/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.caribou/deployment-packages/
21 changes: 21 additions & 0 deletions benchmarks/markdown_to_html/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Empty file.
44 changes: 44 additions & 0 deletions benchmarks/markdown_to_html/app.py
Original file line number Diff line number Diff line change
@@ -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}
24 changes: 24 additions & 0 deletions benchmarks/markdown_to_html/readme.md
Original file line number Diff line number Diff line change
@@ -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
```
4 changes: 4 additions & 0 deletions benchmarks/markdown_to_html/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
markdown
boto3==1.35.3
pyyaml==6.0.2
pytz==2024.1
Empty file.
Empty file.
Loading