Skip to content

Commit 3266d2d

Browse files
authored
Merge pull request #214 from spcl/feature/nosql_storage
Add interface for NoSQL storage
2 parents c71c0b8 + 664d03e commit 3266d2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+3929
-798
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ python-venv
88
cache*
99
!cache.py
1010

11+
minio-volume
12+
scylladb-volume
13+
1114

1215
# Byte-compiled / optimized / DLL files
1316
__pycache__/

.mypy.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ ignore_missing_imports = True
2727
[mypy-google.cloud]
2828
ignore_missing_imports = True
2929

30+
[mypy-google.cloud.logging]
31+
ignore_missing_imports = True
32+
33+
[mypy-google.cloud.monitoring_v3]
34+
ignore_missing_imports = True
35+
36+
[mypy-google.cloud.storage]
37+
ignore_missing_imports = True
38+
3039
[mypy-google.api_core]
3140
ignore_missing_imports = True
3241

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"timeout": 10,
33
"memory": 128,
4-
"languages": ["python", "nodejs"]
4+
"languages": ["python", "nodejs"],
5+
"modules": []
56
}

benchmarks/100.webapps/110.dynamic-html/input.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
'large': 100000
66
}
77

8-
def buckets_count():
9-
return (0, 0)
10-
11-
def generate_input(data_dir, size, benchmarks_bucket, input_paths, output_paths, upload_func):
8+
def generate_input(data_dir, size, benchmarks_bucket, input_paths, output_paths, upload_func, nosql_func):
129
input_config = {'username': 'testname'}
1310
input_config['random_len'] = size_generators[size]
1411
return input_config
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"timeout": 30,
33
"memory": 128,
4-
"languages": ["python", "nodejs"]
4+
"languages": ["python", "nodejs"],
5+
"modules": ["storage"]
56
}

benchmarks/100.webapps/120.uploader/input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def buckets_count():
1212
return (0, 1)
1313

14-
def generate_input(data_dir, size, benchmarks_bucket, input_buckets, output_buckets, upload_func):
14+
def generate_input(data_dir, size, benchmarks_bucket, input_buckets, output_buckets, upload_func, nosql_func):
1515
input_config = {'object': {}, 'bucket': {}}
1616
input_config['object']['url'] = url_generators[size]
1717
input_config['bucket']['bucket'] = benchmarks_bucket
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"timeout": 30,
3+
"memory": 128,
4+
"languages": [
5+
"python",
6+
"nodejs"
7+
],
8+
"modules": [
9+
"nosql"
10+
]
11+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import uuid
2+
3+
4+
def allocate_nosql() -> dict:
5+
return {"shopping_cart": {"primary_key": "cart_id", "secondary_key": "product_id"}}
6+
7+
8+
def generate_input(
9+
data_dir, size, benchmarks_bucket, input_buckets, output_buckets, upload_func, nosql_upload
10+
):
11+
12+
input_config = {}
13+
14+
cart_id = str(uuid.uuid4().hex)
15+
write_cart_id = str(uuid.uuid4().hex)
16+
17+
# Set initial data
18+
19+
nosql_upload(
20+
"130.crud-api",
21+
"shopping_cart",
22+
{"name": "Gothic Game", "price": 42, "quantity": 2},
23+
("cart_id", cart_id),
24+
("product_id", "game-gothic"),
25+
)
26+
nosql_upload(
27+
"130.crud-api",
28+
"shopping_cart",
29+
{"name": "Gothic 2", "price": 142, "quantity": 3},
30+
("cart_id", cart_id),
31+
("product_id", "game-gothic-2"),
32+
)
33+
nosql_upload(
34+
"130.crud-api",
35+
"shopping_cart",
36+
{"name": "SeBS Benchmark", "price": 1000, "quantity": 1},
37+
("cart_id", cart_id),
38+
("product_id", "sebs-benchmark"),
39+
)
40+
nosql_upload(
41+
"130.crud-api",
42+
"shopping_cart",
43+
{"name": "Mint Linux", "price": 0, "quantity": 5},
44+
("cart_id", cart_id),
45+
("product_id", "mint-linux"),
46+
)
47+
48+
requests = []
49+
50+
if size == "test":
51+
# retrieve a single entry
52+
requests.append(
53+
{
54+
"route": "GET /cart/{id}",
55+
"path": {"id": "game-gothic"},
56+
"body": {
57+
"cart": cart_id,
58+
},
59+
}
60+
)
61+
elif size == "small":
62+
requests.append(
63+
{
64+
"route": "GET /cart",
65+
"body": {
66+
"cart": cart_id,
67+
},
68+
}
69+
)
70+
elif size == "large":
71+
# add many new entries
72+
for i in range(5):
73+
requests.append(
74+
{
75+
"route": "PUT /cart",
76+
"body": {
77+
"cart": write_cart_id,
78+
"product_id": f"new-id-{i}",
79+
"name": f"Test Item {i}",
80+
"price": 100 * i,
81+
"quantity": i,
82+
},
83+
}
84+
)
85+
requests.append(
86+
{
87+
"route": "GET /cart",
88+
"body": {
89+
"cart": write_cart_id,
90+
},
91+
}
92+
)
93+
94+
input_config["requests"] = requests
95+
96+
return input_config
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from . import nosql
2+
3+
nosql_client = nosql.nosql.get_instance()
4+
5+
nosql_table_name = "shopping_cart"
6+
7+
8+
def add_product(cart_id: str, product_id: str, product_name: str, price: float, quantity: int):
9+
10+
nosql_client.insert(
11+
nosql_table_name,
12+
("cart_id", cart_id),
13+
("product_id", product_id),
14+
{"price": price, "quantity": quantity, "name": product_name},
15+
)
16+
17+
18+
def get_products(cart_id: str, product_id: str):
19+
return nosql_client.get(nosql_table_name, ("cart_id", cart_id), ("product_id", product_id))
20+
21+
22+
def query_products(cart_id: str):
23+
24+
res = nosql_client.query(
25+
nosql_table_name,
26+
("cart_id", cart_id),
27+
"product_id",
28+
)
29+
30+
products = []
31+
price_sum = 0
32+
quantity_sum = 0
33+
for product in res:
34+
35+
products.append(product["name"])
36+
price_sum += product["price"]
37+
quantity_sum += product["quantity"]
38+
39+
avg_price = price_sum / quantity_sum if quantity_sum > 0 else 0.0
40+
41+
return {"products": products, "total_cost": price_sum, "avg_price": avg_price}
42+
43+
44+
def handler(event):
45+
46+
results = []
47+
48+
for request in event["requests"]:
49+
50+
route = request["route"]
51+
body = request["body"]
52+
53+
if route == "PUT /cart":
54+
add_product(
55+
body["cart"], body["product_id"], body["name"], body["price"], body["quantity"]
56+
)
57+
res = {}
58+
elif route == "GET /cart/{id}":
59+
res = get_products(body["cart"], request["path"]["id"])
60+
elif route == "GET /cart":
61+
res = query_products(body["cart"])
62+
else:
63+
raise RuntimeError(f"Unknown request route: {route}")
64+
65+
results.append(res)
66+
67+
return {"result": results}

0 commit comments

Comments
 (0)