Skip to content

Commit 427018e

Browse files
authored
Reduce memory and s3 costs (#274)
1 parent acdd1dd commit 427018e

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

server/.chalice/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"api_gateway_endpoint_type": "REGIONAL",
55
"minimum_compression_size": 1000,
66
"lambda_timeout": 30,
7-
"lambda_memory_size": 256,
7+
"lambda_memory_size": 220,
88
"layers": [
99
"arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:91"
1010
],

server/chalicelib/last_seen.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ def update_recent_sightings():
2727
all_vehicles = asyncio.run(mbta_api.vehicle_data_for_routes(ROUTES))
2828
new_vehicles = filter_new(all_vehicles)
2929

30-
for vehicle in new_vehicles:
31-
line = get_line_for_route(vehicle["route"])
32-
last_seen_times[line] = {
33-
"car": vehicle["label"],
34-
"time": now.isoformat(),
35-
}
36-
s3.upload(JSON_PATH, json.dumps(last_seen_times), compress=False)
30+
if new_vehicles:
31+
for vehicle in new_vehicles:
32+
line = get_line_for_route(vehicle["route"])
33+
last_seen_times[line] = {
34+
"car": vehicle["label"],
35+
"time": now.isoformat(),
36+
}
37+
s3.upload(JSON_PATH, json.dumps(last_seen_times), compress=False)
3738
except Exception as e:
3839
print("Couldn't write last seen times to s3: ", e)
3940

4041

4142
# Get the last time that a new train was seen on each line
4243
# This is the function that other modules use
4344
def get_recent_sightings_for_lines():
44-
return json.loads(s3.download(JSON_PATH, "utf8"))
45+
return json.loads(s3.download(JSON_PATH, "utf8", compressed=False))

server/chalicelib/mbta_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ async def trip_departure_predictions(trip_id: str, stop_id: str):
123123
# takes a list of route ids
124124
# uses getV3 to request real-time vehicle data for a given route id
125125
# returns list of all vehicles
126-
async def vehicle_data_for_routes(route_ids):
126+
async def vehicle_data_for_routes(route_ids: list[str]):
127127
route_ids = normalize_custom_route_ids(route_ids)
128128

129129
try:

0 commit comments

Comments
 (0)