-
Notifications
You must be signed in to change notification settings - Fork 233
fix: improve query planning time #2303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4164f60
add benchmark
devsergiy 9c245b1
chore: add single test, add example benchmark config
devsergiy 6f33b4a
set tmp version of engine
devsergiy 2899239
chore: do not run benchmark test if there is no config file
devsergiy 2b84bc4
chore: tmp engine version
devsergiy 60a72b3
bump engine
devsergiy ab5bd1c
Merge remote-tracking branch 'origin/main' into sergiy/eng-8285-impro…
devsergiy f12104e
cleanup plan generator
devsergiy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| *.json | ||
| *.txt | ||
| *.out | ||
| *.test |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Planning Benchmark | ||
|
|
||
| Allows to benchmark query planning performance of a single graphql query | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Compose subgraphs to get execution config.json | ||
| - Create `benchmark_config.json` file in the `router/internal/planningbenchmark` directory with the following content: | ||
|
|
||
| ```json | ||
| { | ||
| "executionConfigPath": "<path-to-composed-config.json>", | ||
| "operationPath": "<path-to-graphql-query-file>.graphql", | ||
| } | ||
| ``` | ||
|
|
||
| ## Running the Benchmark | ||
|
|
||
| Run `BenchmarkPlanning` benchmark from benchmark_test.go | ||
|
|
||
| ## Running benchmark using taskfile | ||
|
|
||
| - Modify step name in `router/internal/planningbenchmark/Taskfile.yml` if needed | ||
| - Run `task bench-cpu` from `router/internal/planningbenchmark` directory | ||
| - Profile will be generated in file `<step>_cpu.out` | ||
|
|
||
| You could use different profiles or combine profile. See Taskfile.yml for more details. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| version: '3' | ||
|
|
||
| vars: | ||
| step: bench_planning_01 | ||
|
|
||
| tasks: | ||
| bench: | ||
| go test -benchtime 60s -bench=. -benchmem -memprofile {{.step}}_mem.out -cpuprofile {{.step}}_cpu.out > {{.step}}_benchmark.txt | ||
|
|
||
| bench-cpu: | ||
| go test -benchtime 60s -bench=. -cpuprofile {{.step}}_cpu.out | ||
|
|
||
| bench-mem: | ||
| go test -benchtime 60s -bench=. -memprofile {{.step}}_mem.out | ||
|
|
||
| profile-cpu-web: | ||
| go tool pprof -http=localhost:8080 {{.step}}_cpu.out | ||
|
|
||
| profile-cpu: | ||
| go tool pprof {{.step}}_cpu.out | ||
|
|
||
| profile-mem-web: | ||
| go tool pprof -http=localhost:8080 {{.step}}_mem.out | ||
|
|
||
| profile-mem: | ||
| go tool pprof {{.step}}_mem.out | ||
4 changes: 4 additions & 0 deletions
4
router/internal/planningbenchmark/benchmark_config.json.example
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "executionConfigPath": "", | ||
| "operationPath": "" | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package planningbenchmark | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "go.uber.org/zap" | ||
|
|
||
| "github.com/wundergraph/cosmo/router/core" | ||
| ) | ||
|
|
||
| type BenchmarkConfig struct { | ||
| ExecutionConfigPath string `json:"executionConfigPath"` | ||
| OperationPath string `json:"operationPath"` | ||
| } | ||
|
|
||
| func TestPlanning(t *testing.T) { | ||
| cfgContent, err := os.ReadFile("benchmark_config.json") | ||
| if err != nil { | ||
| t.Skipf("unable to read benchmark_config.json: %v", err) | ||
| } | ||
|
|
||
| var cfg BenchmarkConfig | ||
| require.NoError(t, json.Unmarshal(cfgContent, &cfg)) | ||
|
|
||
| logger := zap.NewNop() | ||
|
|
||
| pg, err := core.NewPlanGenerator(cfg.ExecutionConfigPath, logger, 0) | ||
| require.NoError(t, err) | ||
|
|
||
| pl, err := pg.GetPlanner() | ||
| require.NoError(t, err) | ||
|
|
||
| opDoc, err := pl.ParseAndPrepareOperation(cfg.OperationPath) | ||
| require.NoError(t, err) | ||
|
|
||
| start := time.Now() | ||
| _, err = pl.PlanPreparedOperation(opDoc) | ||
| require.NoError(t, err) | ||
| t.Logf("Planning completed in %v", time.Since(start)) | ||
| } | ||
|
|
||
| func BenchmarkPlanning(b *testing.B) { | ||
| cfgContent, err := os.ReadFile("benchmark_config.json") | ||
| if err != nil { | ||
| b.Skipf("unable to read benchmark_config.json: %v", err) | ||
| } | ||
|
|
||
| var cfg BenchmarkConfig | ||
| require.NoError(b, json.Unmarshal(cfgContent, &cfg)) | ||
|
|
||
| logger := zap.NewNop() | ||
|
|
||
| pg, err := core.NewPlanGenerator(cfg.ExecutionConfigPath, logger, 0) | ||
| require.NoError(b, err) | ||
|
|
||
| pl, err := pg.GetPlanner() | ||
| require.NoError(b, err) | ||
|
|
||
| b.ReportAllocs() | ||
| b.ResetTimer() | ||
|
|
||
| for b.Loop() { | ||
| b.StopTimer() | ||
| opDoc, err := pl.ParseAndPrepareOperation(cfg.OperationPath) | ||
| require.NoError(b, err) | ||
| b.SetBytes(int64(len(opDoc.Input.RawBytes))) | ||
| b.StartTimer() | ||
|
|
||
| _, err = pl.PlanPreparedOperation(opDoc) | ||
| require.NoError(b, err) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.