Skip to content

fix(serving,ci): use shared bounded LIFO upstream pool and run keep-alive tests in CI - #86

Merged
ghchinoy merged 1 commit into
GoogleCloudPlatform:mainfrom
ghchinoy:fix/serving-upstream-lifo-pool-and-ci
Nov 21, 2026
Merged

ghchinoy merged 1 commit into
GoogleCloudPlatform:mainfrom
ghchinoy:fix/serving-upstream-lifo-pool-and-ci

Conversation

@ghchinoy

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #81 addressing the two review items noted before merging:

  1. Shared bounded LIFO upstream HTTP/1.1 keep-alive pool (deploy/cloudrun/server/structured_server.py, deploy/cloudrun/server/dgem.patch):
    • Replaces _UPSTREAM_LOCAL = threading.local() with a lock-guarded, bounded LIFO pool (_UPSTREAM_POOL, capped at max(MAX_INFLIGHT * 2, 16)) so connections are actually reused across read_many worker threads, decide() chunk ThreadPoolExecutors, and per-connection ThreadingHTTPServer handler threads instead of opening a fresh socket per read and leaving it unclosed until GC.
    • Always dials a fresh socket on a stale-socket retry (attempt == 1) so multiple idle closed sockets in the pool cannot burn the single retry.
    • Drops connections on resp.will_close or resp.status >= 500, and adds _close_upstream_pool() for clean teardown.
    • Skips thread creation in read_many when n == 1 (samples: 1 fast path).
  2. Cross-thread & read_many keep-alive regression tests + CI wiring (deploy/cloudrun/server/test_upstream_keepalive_and_logprobs.py, .github/workflows/build.yml, AGENTS.md):
    • Adds tests verifying single-socket reuse across 12 ephemeral threads, read_many reuse for n=1 and n=4 batches, fresh-dial retry with multiple stale pooled sockets, and 5xx socket eviction.
    • Wires deploy/cloudrun/server/test_upstream_keepalive_and_logprobs.py into .github/workflows/build.yml (test-matrix) and AGENTS.md.

Verification

  • ./scripts/regen_serving_patch.sh (clean GNU diff -u regeneration and re-application against structured_server.upstream.py)
  • python3 -W default -m unittest -v deploy/cloudrun/server/test_upstream_keepalive_and_logprobs.py deploy/cloudrun/server/test_server_key.py deploy/cloudrun/server/test_media_fields.py deploy/cloudrun/server/test_upstream_errors.py deploy/cloudrun/server/test_predict_route.py deploy/cloudrun/server/test_ready_route.py (25 tests OK)
  • unset DGEM_VERTEX_URL && go vet ./... && go test ./...
  • python3 -m unittest scripts/matrix/test_matrix.py

@ghchinoy
ghchinoy merged commit 7bd2e19 into GoogleCloudPlatform:main Nov 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant