-
Notifications
You must be signed in to change notification settings - Fork 11
perf: major speed up when querying jobs by tags #429
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
Open
michaeladler
wants to merge
12
commits into
siemens:main
Choose a base branch
from
michaeladler:feat/tags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cb4f5ad
feat(logging): log SQL queries at trace level
michaeladler b4396ef
refactor: use newly introduced Go syntaxes
michaeladler f99ff41
chore: add wfx-loadtest to gitignore
michaeladler 9ed7600
refactor(loadtest): align CLI flags with wfxctl
michaeladler af3cc53
refactor: rename loadtest file
michaeladler 82eb2f0
chore: ignore ui/dist files
michaeladler 8416719
refactor: move initStorage to AppConfig and export it
michaeladler c3fd19e
feat(loadtest): add command to seed database
michaeladler d5cf4ae
perf: major speed up when querying jobs by tags
michaeladler a34c850
chore: take care of nix deprecation
michaeladler 7de51bd
feat(api)!: make pagination metadata opt-in via query parameter
michaeladler 0d83d67
fix: remove retry loops on startup
michaeladler 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| *.pem | ||
| *.generated | ||
| cmd/wfx-viewer/wfx-viewer | ||
| cmd/wfx-loadtest/wfx-loadtest | ||
| /public | ||
| /result | ||
| /dist | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -9,4 +9,4 @@ public | |
| test/test_helper/**/* | ||
| hugo/**/*.html | ||
| **/build | ||
| ui/priv/** | ||
| ui/dist/** | ||
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,48 @@ | ||
| package populate | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "runtime" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/Southclaws/fault" | ||
| "github.com/knadh/koanf/v2" | ||
| "github.com/siemens/wfx/cmd/wfx/cmd/config" | ||
| "github.com/siemens/wfx/persistence" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| flagCount = "count" | ||
| flagWorkers = "workers" | ||
| ) | ||
|
|
||
| func NewCommand(k *koanf.Koanf) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "populate", | ||
| Short: "Populate database with jobs", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return fault.Wrap(run(cmd, k)) | ||
| }, | ||
| } | ||
|
|
||
| f := cmd.Flags() | ||
| f.Int(flagCount, 1000, "number of jobs to create") | ||
| f.Int(flagWorkers, runtime.NumCPU(), "number of concurrent workers") | ||
|
|
||
| supportedStorages := persistence.Storages() | ||
| defaultStorage := supportedStorages[0] | ||
| if slices.Index(supportedStorages, config.PreferedStorage) != -1 { | ||
| defaultStorage = config.PreferedStorage | ||
| } | ||
| f.String(config.StorageFlag, defaultStorage, fmt.Sprintf("persistence storage. one of: [%s]", strings.Join(supportedStorages, ", "))) | ||
|
|
||
| var storageOpts string | ||
| if defaultStorage == config.PreferedStorage { | ||
| storageOpts = config.SqliteDefaultOpts | ||
| } | ||
| f.String(config.StorageOptFlag, storageOpts, "storage options") | ||
|
|
||
| return cmd | ||
| } |
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,84 @@ | ||
| package populate | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math/rand" | ||
| "time" | ||
|
|
||
| "github.com/Southclaws/fault" | ||
| "github.com/knadh/koanf/v2" | ||
| "github.com/rs/zerolog/log" | ||
| "github.com/siemens/wfx/cmd/wfx/cmd/config" | ||
| "github.com/siemens/wfx/generated/api" | ||
| "github.com/siemens/wfx/internal/handler/job/definition" | ||
| "github.com/siemens/wfx/workflow/dau" | ||
| "github.com/spf13/cobra" | ||
| "golang.org/x/sync/errgroup" | ||
| ) | ||
|
|
||
| func run(cmd *cobra.Command, k *koanf.Koanf) error { | ||
| ctx := cmd.Context() | ||
|
|
||
| appConfig, err := config.NewAppConfig(cmd.Flags()) | ||
| if err != nil { | ||
| return fault.Wrap(err) | ||
| } | ||
|
|
||
| storage, err := appConfig.InitStorage() | ||
| if err != nil { | ||
| return fault.Wrap(err) | ||
| } | ||
|
|
||
| wf := dau.DirectWorkflow() | ||
| wfExisting, err := storage.GetWorkflow(ctx, wf.Name) | ||
| if err != nil { | ||
| return fault.Wrap(err) | ||
| } | ||
| if wfExisting == nil { | ||
| if _, err := storage.CreateWorkflow(ctx, wf); err != nil { | ||
| return fault.Wrap(err) | ||
| } | ||
| log.Info().Str("name", wf.Name).Msg("Created workflow") | ||
| } else { | ||
| log.Info().Str("name", wf.Name).Msg("Worfklow already exists") | ||
| } | ||
|
|
||
| count := k.Int(flagCount) | ||
| workers := k.Int(flagWorkers) | ||
| log.Info().Int("count", count).Int("workers", workers).Msg("Populating storage with jobs") | ||
|
|
||
| tags := []string{"EUROPE_WEST", "loadtest"} | ||
|
|
||
| g, ctx := errgroup.WithContext(ctx) | ||
| g.SetLimit(workers) | ||
| for i := range count { | ||
| g.Go(func() error { | ||
| now := time.Now() | ||
| clientID := fmt.Sprintf("LOAD-%d", i) | ||
| state := wf.States[rand.Intn(len(wf.States))] // pick random state | ||
| job := api.Job{ | ||
| ClientID: clientID, | ||
| Workflow: wf, | ||
| Mtime: &now, | ||
| Stime: &now, | ||
| Status: &api.JobStatus{ | ||
| ClientID: clientID, | ||
| State: state.Name, | ||
| }, | ||
| Definition: map[string]any{}, | ||
| Tags: &tags, | ||
| History: &[]api.History{}, | ||
| } | ||
| job.Status.DefinitionHash = definition.Hash(&job) | ||
| _, err := storage.CreateJob(ctx, &job) | ||
| return fault.Wrap(err) | ||
| }) | ||
| } | ||
| if err := g.Wait(); err != nil { | ||
| return fault.Wrap(err) | ||
| } | ||
|
|
||
| log.Info().Int("count", count).Msg("Finished populating storage with jobs") | ||
|
|
||
| return nil | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.