Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions router/pkg/plan_generator/plan_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ func PlanGenerator(ctx context.Context, cfg QueryPlanConfig) error {
for i := 0; i < cfg.Concurrency; i++ {
go func(i int) {
defer wg.Done()
planner, err := pg.GetPlanner()
if err != nil {
// if we fail to get the planner, we need to cancel the context to stop the other goroutines
// and return here to stop the current goroutine
cancelError(fmt.Errorf("failed to get planner: %v", err))
return
}
for {
select {
case <-ctxError.Done():
Expand All @@ -146,6 +139,15 @@ func PlanGenerator(ctx context.Context, cfg QueryPlanConfig) error {

queryFilePath := filepath.Join(queriesPath, queryFile.Name())

// Planners should not be reused.
planner, err := pg.GetPlanner()
if err != nil {
// If we fail to get the planner, we have to cancel the context
// to stop this and the other goroutines via ctxError.
cancelError(fmt.Errorf("failed to get a planner: %v", err))
Comment thread
endigma marked this conversation as resolved.
Outdated
return
}

outContent, opTimes, err := planner.PlanOperation(queryFilePath, cfg.OutputFormat)
res := QueryPlanResult{
FileName: queryFile.Name(),
Expand Down
19 changes: 19 additions & 0 deletions router/pkg/plan_generator/plan_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,22 @@ func TestPlanGenerator(t *testing.T) {
})

}

func BenchmarkPlanGenerator(b *testing.B) {
tempDir := b.TempDir()
cfg := QueryPlanConfig{
SourceDir: path.Join(getTestDataDir(), "queries", "bench"),
OutDir: tempDir,
ExecutionConfig: path.Join(getTestDataDir(), "execution_config", "base.json"),
Timeout: "30s",
Concurrency: 1,
}
b.ReportAllocs()
b.ResetTimer()
Comment thread
endigma marked this conversation as resolved.
Outdated
for b.Loop() {
err := PlanGenerator(context.Background(), cfg)
if err != nil {
b.Fatal(err)
}
}
}
125 changes: 125 additions & 0 deletions router/pkg/plan_generator/testdata/queries/bench/full.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
query Full {
employees {
# resolved through employees subgraph
id
# overridden by the products subgraph
notes
details {
# resolved through either employees or family subgraph
forename
surname
# resolved through employees subgraph
location {
language
}
# resolved through family subgraph
hasChildren
# maritalStatus can return null
maritalStatus
nationality
# pets can return null
pets {
class
gender
name
... on Cat {
type
}
... on Dog {
breed
}
... on Alligator {
dangerous
}
}
}
# resolved through employees subgraph
role {
departments
title
... on Engineer {
engineerType
}
... on Operator {
operatorType
}
}
# resolved through hobbies subgraph
hobbies {
... on Exercise {
category
}
... on Flying {
planeModels
yearsOfExperience
}
... on Gaming {
genres
name
yearsOfExperience
}
... on Other {
name
}
... on Programming {
languages
}
... on Travelling {
countriesLived {
language
key {
name
}
}
}
}
# resolved through products subgraph
products
}
# can return null
employee(id: 1) {
# resolved through employees subgraph
id
details {
forename
location {
language
}
}
}
teammates(team: OPERATIONS) {
# resolved through employees subgraph
id
...EmployeeNameFragment
# resolved through products subgraph
products
}
productTypes {
... on Documentation {
url(product: SDK)
urls(products: [COSMO, MARKETING])
}
... on Consultancy {
lead {
...EmployeeNameFragment
}
name
}
}
a: findEmployees(criteria: {
hasPets: true, nationality: UKRAINIAN, nested: { maritalStatus: ENGAGED }
}) {
...EmployeeNameFragment
}
b: findEmployees(criteria: {
hasPets: true, nationality: GERMAN, nested: { maritalStatus: MARRIED, hasChildren: true }
}) {
...EmployeeNameFragment
}
}

fragment EmployeeNameFragment on Employee {
details {
forename
}
}
Loading