Skip to content

Commit

Permalink
Experiment 8 - Determine chunk size
Browse files Browse the repository at this point in the history
- AWS: Read 1B for every 4096B, 8192B, 16384B, 32768B, for exactly 1024 bytes
- Azure: Read 1B for every 4096B, 8192B for exactly 1024 bytes
- GCR: Read 1B for every 40kB, 48kB, 56kB for exactly 1024 bytes
  • Loading branch information
ypwong99 committed Feb 15, 2024
1 parent 2bb758b commit 9a19c8e
Show file tree
Hide file tree
Showing 13 changed files with 594 additions and 111 deletions.
359 changes: 250 additions & 109 deletions .github/workflows/chunk-size-experiment.yml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Runtime": "python3.9",
"SubExperiments": [
{
"Title": "cold-100-aws-read-per-16384-bytes",
"Title": "aws-chunk-16-kbytes",
"Function": "hellopy-read-per-16384-bytes",
"Handler": "main.lambda_handler",
"PackageType": "Zip",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Runtime": "python3.9",
"SubExperiments": [
{
"Title": "cold-100-aws-read-per-32768-bytes",
"Title": "aws-chunk-32-kbytes",
"Function": "hellopy-read-per-32768-bytes",
"Handler": "main.lambda_handler",
"PackageType": "Zip",
Expand Down
23 changes: 23 additions & 0 deletions experiments/image-size/aws-chunk-4-kbytes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Provider": "aws",
"Runtime": "python3.9",
"SubExperiments": [
{
"Title": "aws-chunk-16-kbytes",
"Function": "hellopy-read-per-16384-bytes",
"Handler": "main.lambda_handler",
"PackageType": "Zip",
"PackagePattern": "main.py",
"Bursts": 500,
"BurstSizes": [
1
],
"IATSeconds": 600,
"DesiredServiceTimes": [
"0ms"
],
"Parallelism": 50,
"FunctionImageSizeMB": 100
}
]
}
23 changes: 23 additions & 0 deletions experiments/image-size/aws-chunk-8-kbytes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"Provider": "aws",
"Runtime": "python3.9",
"SubExperiments": [
{
"Title": "aws-chunk-16-kbytes",
"Function": "hellopy-read-per-16384-bytes",
"Handler": "main.lambda_handler",
"PackageType": "Zip",
"PackagePattern": "main.py",
"Bursts": 500,
"BurstSizes": [
1
],
"IATSeconds": 600,
"DesiredServiceTimes": [
"0ms"
],
"Parallelism": 50,
"FunctionImageSizeMB": 100
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
import os
import time
import random


def lambda_handler(request, context):
incr_limit = 0

if 'queryStringParameters' in request and 'IncrementLimit' in request['queryStringParameters']:
incr_limit = int(request['queryStringParameters'].get('IncrementLimit', 0))
elif 'body' in request and json.loads(request['body'])['IncrementLimit']:
incr_limit = int(json.loads(request['body'])['IncrementLimit'])

simulate_work(incr_limit)
read_filler_file('./filler.file')

json_region = os.environ.get('AWS_REGION', 'Unknown')

response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": json.dumps({
"Region ": json_region,
"RequestID": context.aws_request_id,
"TimestampChain": [str(time.time_ns())]
}, indent=4)
}

return response


def simulate_work(increment):
# MAXNUM = 6103705
num = 0
while num < increment:
num += 1


def read_filler_file(path: str) -> None:
with open(path, 'rb') as f:
for i in range(1024):
f.seek(i * 4096)
f.read(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
import os
import time
import random


def lambda_handler(request, context):
incr_limit = 0

if 'queryStringParameters' in request and 'IncrementLimit' in request['queryStringParameters']:
incr_limit = int(request['queryStringParameters'].get('IncrementLimit', 0))
elif 'body' in request and json.loads(request['body'])['IncrementLimit']:
incr_limit = int(json.loads(request['body'])['IncrementLimit'])

simulate_work(incr_limit)
read_filler_file('./filler.file')

json_region = os.environ.get('AWS_REGION', 'Unknown')

response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": json.dumps({
"Region ": json_region,
"RequestID": context.aws_request_id,
"TimestampChain": [str(time.time_ns())]
}, indent=4)
}

return response


def simulate_work(increment):
# MAXNUM = 6103705
num = 0
while num < increment:
num += 1


def read_filler_file(path: str) -> None:
with open(path, 'rb') as f:
for i in range(1024):
f.seek(i * 8192)
f.read(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
import os
import time
import random

import azure.functions as func


def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
incr_limit = int(req.params.get('IncrementLimit')) if req.params.get('IncrementLimit') else None
if not incr_limit:
try:
req_body = req.get_json()
except ValueError:
incr_limit = 0
pass
else:
incr_limit = int(req_body.get('IncrementLimit')) if req_body.get('IncrementLimit') else 0
else:
incr_limit = 0

simulate_work(incr_limit)
read_filler_file(f"{context.function_directory}/../filler.file")

return func.HttpResponse(
body=json.dumps({
"RequestID": context.invocation_id,
"TimestampChain": [str(time.time_ns())]
}, indent=4),
status_code=200,
headers={
"Content-Type": "application/json"
}
)


def simulate_work(increment):
# MAXNUM = 6103705
num = 0
while num < increment:
num += 1


def read_filler_file(path: str) -> None:
with open(path, 'rb') as f:
for i in range(1024):
f.seek(i * 4096)
f.read(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
import os
import time
import random

import azure.functions as func


def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
incr_limit = int(req.params.get('IncrementLimit')) if req.params.get('IncrementLimit') else None
if not incr_limit:
try:
req_body = req.get_json()
except ValueError:
incr_limit = 0
pass
else:
incr_limit = int(req_body.get('IncrementLimit')) if req_body.get('IncrementLimit') else 0
else:
incr_limit = 0

simulate_work(incr_limit)
read_filler_file(f"{context.function_directory}/../filler.file")

return func.HttpResponse(
body=json.dumps({
"RequestID": context.invocation_id,
"TimestampChain": [str(time.time_ns())]
}, indent=4),
status_code=200,
headers={
"Content-Type": "application/json"
}
)


def simulate_work(increment):
# MAXNUM = 6103705
num = 0
while num < increment:
num += 1


def read_filler_file(path: str) -> None:
with open(path, 'rb') as f:
for i in range(1024):
f.seek(i * 8192)
f.read(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.7-alpine

RUN pip install Flask gunicorn

WORKDIR /app
COPY . .

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
import os
import time
from flask import Flask, request

app = Flask(__name__)


@app.route('/')
def hello_world():
incr_limit = 0
if request.args and 'incrementLimit' in request.args:
incr_limit = request.args.get('incrementLimit')

simulate_work(incr_limit)
read_filler_file("./filler.file")

response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"RequestID": "gcr-does-not-specify",
"TimestampChain": [str(time.time_ns())],
}
}

return json.dumps(response, indent=4)


def simulate_work(incr):
num = 0
while num < incr:
num += 1


def read_filler_file(path: str) -> None:
with open(path, 'rb') as f:
for i in range(1024):
f.seek(i * 40960)
f.read(1)


if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.7-alpine

RUN pip install Flask gunicorn

WORKDIR /app
COPY . .

CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
import os
import time
from flask import Flask, request

app = Flask(__name__)


@app.route('/')
def hello_world():
incr_limit = 0
if request.args and 'incrementLimit' in request.args:
incr_limit = request.args.get('incrementLimit')

simulate_work(incr_limit)
read_filler_file("./filler.file")

response = {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"RequestID": "gcr-does-not-specify",
"TimestampChain": [str(time.time_ns())],
}
}

return json.dumps(response, indent=4)


def simulate_work(incr):
num = 0
while num < incr:
num += 1


def read_filler_file(path: str) -> None:
with open(path, 'rb') as f:
for i in range(1024):
f.seek(i * 57344)
f.read(1)


if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))

0 comments on commit 9a19c8e

Please sign in to comment.