Skip to content

Commit

Permalink
Debug why streamining hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-baseten committed Aug 28, 2024
1 parent 47cecfc commit 83d3c4e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions truss/templates/server/common/truss_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ async def predict(
model: ModelWrapper = self._safe_lookup_model(model_name)

self.check_healthy(model)
# TODO: warn (or skip tracing), if no parent info was found?
trace_ctx = otel_propagate.extract(request.headers)

print(f"############\n{request.headers}")

trace_ctx = otel_propagate.extract(request.headers) or None
# This is the top-level span in the truss-server, so we set the context here.
# Nested spans "inherit" context automatically.
with self._tracer.start_as_current_span(
Expand Down
4 changes: 3 additions & 1 deletion truss/templates/server/model_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def try_load(self):
retry(
self._model.load,
NUM_LOAD_RETRIES,
self._logger.warn,
self._logger.warning,
"Failed to load model.",
gap_seconds=1.0,
)
Expand Down Expand Up @@ -301,6 +301,7 @@ async def write_response_to_queue(
)
finally:
await queue.put(None)
print("@@@@@@@@ done write_response_to_queue")

async def _gather_generator(self, response: Any, span: trace.Span) -> str:
# In the case of gathering, it might make more sense to apply the postprocess
Expand Down Expand Up @@ -345,6 +346,7 @@ async def _stream_with_background_task(
self.write_response_to_queue(response_queue, async_generator, span)
)
# Defer the release of the semaphore until the write_response_to_queue task.
print("@@@@@@@@ add delayed release")
gen_task.add_done_callback(lambda _: release_and_end)

# The gap between responses in a stream must be < streaming_read_timeout
Expand Down

0 comments on commit 83d3c4e

Please sign in to comment.