recomendationservice: disable tracing b/c memleak
enabling the tracing interceptor/sampler causes an unbounded memory leak eventually OOMing the container. Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
2c8681d324
commit
316db889aa
1 changed files with 29 additions and 19 deletions
|
@ -6,13 +6,14 @@ import time
|
|||
import random
|
||||
import os
|
||||
|
||||
from opencensus.trace.ext.grpc import server_interceptor
|
||||
from opencensus.trace.samplers import always_on
|
||||
from opencensus.trace.exporters import stackdriver_exporter
|
||||
from opencensus.trace.exporters import print_exporter
|
||||
|
||||
import googleclouddebugger
|
||||
|
||||
# TODO(morganmclean,ahmetb) tracing currently disabled due to memory leak (see TODO below)
|
||||
# from opencensus.trace.ext.grpc import server_interceptor
|
||||
# from opencensus.trace.samplers import always_on
|
||||
# from opencensus.trace.exporters import stackdriver_exporter
|
||||
# from opencensus.trace.exporters import print_exporter
|
||||
|
||||
class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
||||
def ListRecommendations(self, request, context):
|
||||
max_responses = 5
|
||||
|
@ -26,47 +27,56 @@ class RecommendationService(demo_pb2_grpc.RecommendationServiceServicer):
|
|||
indices = random.sample(range(num_products), num_return)
|
||||
# fetch product ids from indices
|
||||
prod_list = [filtered_products[i] for i in indices]
|
||||
print("handling request: {}".format(prod_list))
|
||||
print("[Recv ListRecommendations] product_ids={}".format(prod_list))
|
||||
# build and return response
|
||||
response = demo_pb2.ListRecommendationsResponse()
|
||||
response.product_ids.extend(prod_list)
|
||||
return response
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("starting recommendationservice")
|
||||
try:
|
||||
sampler = always_on.AlwaysOnSampler()
|
||||
exporter = stackdriver_exporter.StackdriverExporter()
|
||||
tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(sampler, exporter)
|
||||
except:
|
||||
tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()
|
||||
print("initializing recommendationservice")
|
||||
|
||||
# TODO(morganmclean,ahmetb) enabling the tracing interceptor/sampler below
|
||||
# causes an unbounded memory leak eventually OOMing the container.
|
||||
# ----
|
||||
# try:
|
||||
# sampler = always_on.AlwaysOnSampler()
|
||||
# exporter = stackdriver_exporter.StackdriverExporter()
|
||||
# tracer_interceptor = server_interceptor.OpenCensusServerInterceptor(sampler, exporter)
|
||||
# except:
|
||||
# tracer_interceptor = server_interceptor.OpenCensusServerInterceptor()
|
||||
|
||||
try:
|
||||
googleclouddebugger.enable(
|
||||
module='recommendationserver',
|
||||
version='1.0.0'
|
||||
)
|
||||
except:
|
||||
except Exception, err:
|
||||
print("could not enable debugger")
|
||||
traceback.print_exc()
|
||||
pass
|
||||
|
||||
# get port from $PORT envar
|
||||
port = os.environ.get('PORT', "8080")
|
||||
# get product catalog service address from $PRODUCT_CATALOG_SERVICE_ADDR envar
|
||||
catalog_addr = os.environ.get('PRODUCT_CATALOG_SERVICE_ADDR', '')
|
||||
if catalog_addr == "":
|
||||
raise Exception('PRODUCT_CATALOG_SERVICE_ADDR environment not set')
|
||||
raise Exception('PRODUCT_CATALOG_SERVICE_ADDR environment variable not set')
|
||||
print("product catalog address: " + catalog_addr)
|
||||
print("listening on port: " + port)
|
||||
|
||||
# stub for product catalog service
|
||||
channel = grpc.insecure_channel(catalog_addr)
|
||||
stub = demo_pb2_grpc.ProductCatalogServiceStub(channel)
|
||||
|
||||
# create gRPC server
|
||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),interceptors=(tracer_interceptor,))
|
||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) # ,interceptors=(tracer_interceptor,))
|
||||
|
||||
# add class to gRPC server
|
||||
demo_pb2_grpc.add_RecommendationServiceServicer_to_server(RecommendationService(), server)
|
||||
|
||||
# start server
|
||||
print("listening on port: " + port)
|
||||
server.add_insecure_port('[::]:'+port)
|
||||
server.start()
|
||||
|
||||
# keep alive
|
||||
try:
|
||||
while True:
|
||||
|
|
Loading…
Reference in a new issue