Repository navigation
Conversation
Every request built an http.ServeMux, registered the session's four endpoints on it and dispatched through it, and built the fields of a Debug log entry whether or not debug logging was on. The session's endpoints are exact paths, so while the session has no endpoint mixed in through MuxEndpoint, a request for one of them is now served directly. Any other request goes through the mux with every endpoint registered, as before, so a mixed-in pattern that matches a built-in path, such as "GET /query", keeps its precedence. The debug entry is built only when debug logging is enabled. Signed-off-by: Erik Sipsma <[email protected]>
Every request chained five logrus WithField calls, each copying the entry's growing field map, and formatted its trace and span IDs four times over. The fields are now set in one WithFields call, from IDs formatted once. Signed-off-by: Erik Sipsma <[email protected]>
Every request of a client runs mergeClientMetadataLocked, which cloned the incoming metadata through a JSON round trip before comparing it with the stored one, field by field. For a known client the two almost always match and nothing is stored, so the clone is now made only once a field must be completed from the incoming metadata: the record still never shares a value with the caller. getOrInitClient, the only caller outside tests, passes metadata it has already cloned the same way, so the comparisons are those of a cloned value as before. Signed-off-by: Erik Sipsma <[email protected]>
Every request of a session took the engine's sessions lock exclusively, only to find its session in the map. With a dozen requests of a build in flight, they queued on it: in execution traces of two edit builds of dagger's CLI, requests waited on it 15 ms and 0.2 s in all. An existing session is now found under the read lock; only a request that creates a session takes the write lock, and checks for shutdown under it as before. Signed-off-by: Erik Sipsma <[email protected]>
…request Every query built a new gqlgen server for its schema: five transports, the introspection and persisted-query extensions, a cache of parsed queries and a cache of persisted queries, all dropped once the request was served. A dagql.Server now builds its handler on first use and serves every request to its schema with it. The handler is gqlgen's default server, written out instead of taken from the deprecated handler.NewDefaultServer, without its cache of parsed queries. That cache never hit before, since each lived for one request, and shared it would mostly hold queries that never come again: clients write their arguments, IDs included, into the query text. The persisted-query cache is now shared by the schema's requests, so a client using automatic persisted queries can send a known query by its hash alone, as that extension intends. Signed-off-by: Erik Sipsma <[email protected]>
serveHTTPToClient logged a debug entry for every request, added to help debug a transport error (#7592, closed since). The engine logs at debug level by default, so every engine formatted and wrote that line for every GraphQL request: in an edit build of dagger's CLI, a few thousand lines and 0.03 to 0.06 CPU-s. The entry is now logged at trace level, where it's still there to debug with. Signed-off-by: Erik Sipsma <[email protected]>
Contributor
Author
|
Folded into #15007, which carries these six commits unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every Dagger client talks to the engine through GraphQL over HTTP, one request per query. Before a request reaches dagql, the engine routes it, admits its client, sets up its loggers and builds a GraphQL handler. Several of those steps redo, for every request, work whose result never changes. That is cheap once, but a build that makes thousands of cached calls pays it thousands of times. Building dagger's own CLI with dagger/go is an example: an edit sends ~3,000 requests.
This PR removes that repeated work. It cuts the engine's CPU by ~0.2–0.3 s per edit build of dagger's CLI with dagger/go, about 4–5% of the engine's CPU for that build. On its own, no build's wall time changes, because on an edit another step ties with the request walk on the critical path. With in-flight changes that shorten that other step, edits are ~0.13–0.20 s faster.
What changes
Each commit stands on its own:
serveHTTPToClientbuilt anhttp.ServeMuxfor every request and registered the session's four endpoints on it. Those are exact paths, so they're now served directly. The mux is still built for telemetry subscriptions, and for every request once the session has an endpoint mixed in throughMuxEndpoint, so a mixed-in pattern keeps its precedence.WithFieldcalls, each copying logrus's field map; it now gets them in oneWithFieldscall.mergeClientMetadataLockedmade a JSON round-trip clone of the incoming metadata on every request, under the session's scope lock, only to find nothing to store. It now compares first and clones only a field it stores.getOrInitClient's own clone stays: it also normalizes the metadata (an empty map becomes nil), and the comparison relies on that.daggerSessionsMuexclusively to find its session. Now only creating a session takes the write lock, and the shutdown check stays under it. Execution traces of an edit build showed requests waiting up to 0.2 s in all on that lock.serveQuerybuilt a new gqlgen server per request: five transports, two extensions and two LRU caches, all thrown away afterwards. Adagql.Servernow builds its handler on first use and every request to that schema shares it.handler.NewDefaultServeris deprecated. It has no parsed-query cache: that cache never hit when it lived for one request, and shared, it would mostly hold queries that never come again, since the SDKs write arguments, IDs included, into the query text.Measurements
Building dagger's CLI with dagger/go on one c8gd.4xlarge (16 Graviton4 cores), comparing an engine with and without this change, both built from the same base. Every run started a fresh engine, with alternating arms. There were three series on one machine: 4 runs per arm (without the last commit), then 8, then 6 with the engine's wall-clock profiler recording in both arms. The base was a branch of main with other performance changes on it; this series applies to main with an identical diff.
Engine CPU, s per build, change minus base, with 95% intervals:
Wall time, all 18 runs per arm pooled, change minus base:
A fourth series put both arms on top of in-flight changes that take the source's content hash off the edit's critical path, 8 runs per arm. On that line, edits were 0.13–0.20 s faster (medians), with intervals of −0.30 to −0.05 s and −0.25 to −0.06 s.
CPU profiles of one run per arm show the targeted steps shrink. Building a mux per request went from 0.08–0.10 CPU-s per build to nothing, building gqlgen's handler from 0.03–0.04 to nothing, and client admission from 0.07 to 0.03 per edit.
Validation
dagger api call engine-dev test --pkg ./engine/server --race: 497 passed.dagger api call engine-dev test --pkg ./dagql --race: 1,248 passed.test-split/test-packagescheck.