Skip to content

Commit fca6c27

Browse files
Merge pull request #8 from AlexanderWert/fix/recommendation-cache-memory-bloat
fix: revert buggy recommendation cache causing memory bloat and latency spike
2 parents 375a36e + d9f1b31 commit fca6c27

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

src/recommendation/recommendation_server.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
)
3838

3939
first_run = True
40-
cached_ids = []
41-
cached_ids_to_retrieve_recommendations_for = []
42-
MAX_CACHED_IDS = 2000000
4340

4441
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
4542
def ListRecommendations(self, request, context):
@@ -65,31 +62,6 @@ def Watch(self, request, context):
6562
return health_pb2.HealthCheckResponse(
6663
status=health_pb2.HealthCheckResponse.UNIMPLEMENTED)
6764

68-
def get_recommendations_ids(request_product_ids):
69-
global cached_ids
70-
71-
with tracer.start_as_current_span("get_recommendations_ids") as span:
72-
can_retrieve_from_cache = True
73-
for p_id in request_product_ids:
74-
if p_id not in cached_ids_to_retrieve_recommendations_for:
75-
can_retrieve_from_cache = False
76-
77-
if not can_retrieve_from_cache:
78-
logger.info("get_recommendations_ids: cache miss")
79-
span.set_attribute("app.cache_hit", False)
80-
cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty())
81-
ids_to_add = []
82-
for x in cat_response.products:
83-
ids_to_add.extend(cached_ids)
84-
ids_to_add.append(x.id)
85-
if len(ids_to_add) + len(cached_ids) < MAX_CACHED_IDS:
86-
cached_ids= cached_ids + ids_to_add
87-
return cached_ids
88-
else:
89-
logger.info("get_recommendations_ids: cache hit")
90-
span.set_attribute("app.cache_hit", True)
91-
return cached_ids
92-
9365
def get_product_list(request_product_ids):
9466
global first_run
9567
with tracer.start_as_current_span("get_product_list") as span:
@@ -99,7 +71,8 @@ def get_product_list(request_product_ids):
9971
request_product_ids_str = ''.join(request_product_ids)
10072
request_product_ids = request_product_ids_str.split(',')
10173

102-
product_ids = get_recommendations_ids(request_product_ids)
74+
cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty())
75+
product_ids = [x.id for x in cat_response.products]
10376

10477
span.set_attribute("app.products.count", len(product_ids))
10578

0 commit comments

Comments
 (0)