chore(http-client): cleanup types, improve coverage, remove orjson#157
chore(http-client): cleanup types, improve coverage, remove orjson#157
Conversation
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily focuses on a significant refactor of the HTTP client, aiming to streamline its interface and improve internal consistency. A major part of this effort involved migrating from the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Pull request overview
This PR removes the orjson dependency and migrates JSON encoding/decoding to msgspec, while also simplifying the HTTP endpoint client API (consolidating the async/sync client split) and expanding integration coverage for polling/receiving/draining responses.
Changes:
- Replace
orjsonusage withmsgspec.jsonacross metrics, evaluation, loadgen reporting, and tests. - Refactor the HTTP endpoint client to a single
HTTPEndpointClientand update benchmarks/exports accordingly. - Add integration tests covering
poll(),recv(),drain(), andshutdown()behavior.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/metrics/test_reporter.py | Switch test event payload encoding from orjson to msgspec.json. |
| tests/unit/metrics/test_recorder.py | Update unit tests to use msgspec.json.encode/decode for event row data. |
| tests/integration/endpoint_client/test_http_client.py | Add integration tests for poll/recv/drain/shutdown and client fixture helpers. |
| tests/conftest.py | Update test DB fixtures to encode JSON via msgspec.json. |
| src/inference_endpoint/utils/benchmark_httpclient.py | Update benchmark to use HTTPEndpointClient and sync shutdown. |
| src/inference_endpoint/openai/openai_adapter.py | Migrate request/response JSON encode/decode to msgspec. |
| src/inference_endpoint/metrics/reporter.py | Replace JSON dump/load operations with msgspec.json formatting/decoding. |
| src/inference_endpoint/metrics/recorder.py | Use msgspec.json.encode and msgspec.EncodeError in event recording. |
| src/inference_endpoint/load_generator/session.py | Write JSON artifacts using msgspec formatting/encoding. |
| src/inference_endpoint/evaluation/scoring.py | Replace JSON parsing/serialization with msgspec.json and update error handling. |
| src/inference_endpoint/endpoint_client/worker.py | Simplify request/response handling and rely on idempotent pool release. |
| src/inference_endpoint/endpoint_client/http_sample_issuer.py | Remove redundant loop assertion when scheduling response handler. |
| src/inference_endpoint/endpoint_client/http_client.py | Consolidate client class and make shutdown synchronous via internal async helper. |
| src/inference_endpoint/endpoint_client/http.py | Make ConnectionPool.release() explicitly idempotent; adjust InFlightRequest typing. |
| src/inference_endpoint/endpoint_client/config.py | Make adapter/accumulator/transport “defaulted in post_init” (typing adjustments). |
| src/inference_endpoint/endpoint_client/init.py | Update exports to only expose HTTPEndpointClient. |
| pyproject.toml | Remove orjson dependency (keep msgspec). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| Usage: | ||
| with ManagedZMQContext.scoped() as zmq_ctx: | ||
| client = AsyncHttpEndpointClient(config, zmq_context=zmq_ctx) | ||
| client = HTTPEndpointClient(config, zmq_context=zmq_ctx) | ||
| client.issue(query) | ||
| response = await client.recv() | ||
| await client.shutdown() | ||
| response = client.poll() # Non-blocking, returns None if nothing ready | ||
| responses = client.drain() # Drain all available responses | ||
| # response = await client.recv() # Blocking; only if caller provides its own loop | ||
| client.shutdown() # Blocks until workers stop | ||
| """ |
There was a problem hiding this comment.
Now that AsyncHttpEndpointClient/HTTPEndpointClient have been collapsed into a single class that typically owns a background event-loop thread (LoopManager.create_loop for non-"default" loops), the public issue() method needs to be thread-safe. With ZmqWorkerPoolTransport, send() may call loop.add_writer() via _ZmqSenderTransport, which must run on the event loop thread; calling it directly from the caller thread can sporadically raise or misbehave under backpressure.
Make issue() schedule the actual pool.send(next(self._worker_cycle), query) onto self.loop via call_soon_threadsafe (and advance the cycle on that same thread).
What does this PR do?
Type of change
Related issues
Testing
Checklist