-
Notifications
You must be signed in to change notification settings - Fork 13
Run mongodb-benchmarking
#1255
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
chilagrow
wants to merge
44
commits into
FerretDB:main
Choose a base branch
from
chilagrow:mongodb-benchmarking
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
Run mongodb-benchmarking
#1255
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
81ff782
go.mod
chilagrow 8f28c00
add as replacement file directive
chilagrow a9f26bb
mongobench package
chilagrow 395c882
parsing
chilagrow dfde50b
file is not valid csv
chilagrow 3234b1e
comment and example
chilagrow 9e07c18
gitignore
chilagrow 3d9f81e
lint
chilagrow 779d885
make it run
chilagrow 3e72a3f
allow pushing array of results
chilagrow 580b57b
allow flexibility to the way measurements are pushed
chilagrow da52444
config
chilagrow ec091fb
lint
chilagrow ded39d4
resolve merge conflict
chilagrow 777922e
check nil
chilagrow 20986fd
test
chilagrow bd7d2ea
Merge branch 'pusher-measurement-interface' into mongodb-benchmarking
chilagrow 8639d2d
workaround
chilagrow 4a81d99
comment
chilagrow 001b791
use fork
chilagrow 57b8e4e
lint
chilagrow 24e1596
tooling
chilagrow c5c81cc
Merge branch 'mongodb-benchmarking-tooling' into mongodb-benchmarking
chilagrow afe5c7e
interface check
chilagrow b738d6c
run in CI
chilagrow 221fbe1
no ferretdb v1
chilagrow 029d36c
file path
chilagrow 1c26d6f
fix
chilagrow 1b5a43d
Update internal/runner/mongobench/mongobench.go
chilagrow 5715b6e
Do not use git submodule
AlekSi 32ebf5d
undo workflow changes
chilagrow 308d32b
Merge branch 'mongodb-benchmarking-tooling' into mongodb-benchmarking
chilagrow f489f0e
update
chilagrow 70c9c9c
Merge branch 'mongodb-benchmarking' of github.com:chilagrow/dance int…
chilagrow bf2931f
Merge branch 'main' into mongodb-benchmarking
chilagrow 0e52d40
report last resutl
chilagrow 561d8bd
comment
chilagrow ad06952
Merge branch 'main' into mongodb-benchmarking
chilagrow 303fd37
copilot
chilagrow dba2454
Merge branch 'main' into mongodb-benchmarking
AlekSi 8f154cc
Merge branch 'main' into mongodb-benchmarking
AlekSi aed63f8
Merge branch 'main' into mongodb-benchmarking
AlekSi 9b386bf
Merge branch 'main' into mongodb-benchmarking
AlekSi 53b5533
Merge branch 'main' into mongodb-benchmarking
chilagrow 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
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 |
|---|---|---|
|
|
@@ -3,3 +3,6 @@ | |
| /dumps/mongodump_tests/ | ||
| /vendor/ | ||
| cover.txt | ||
|
|
||
| # mongodb-benchmarking | ||
| projects/benchmark_results_*.csv | ||
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,216 @@ | ||||||
| // Copyright 2021 FerretDB Inc. | ||||||
| // | ||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| // you may not use this file except in compliance with the License. | ||||||
| // You may obtain a copy of the License at | ||||||
| // | ||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| // | ||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
|
|
||||||
| // Package mongobench provides `mongobench` runner. | ||||||
| package mongobench | ||||||
|
|
||||||
| import ( | ||||||
| "bufio" | ||||||
| "context" | ||||||
| "errors" | ||||||
| "io" | ||||||
| "log/slog" | ||||||
| "os" | ||||||
| "os/exec" | ||||||
| "path/filepath" | ||||||
| "strconv" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/FerretDB/dance/internal/config" | ||||||
| "github.com/FerretDB/dance/internal/runner" | ||||||
| ) | ||||||
|
|
||||||
| // mongoBench represents `mongoBench` runner. | ||||||
| type mongoBench struct { | ||||||
| p *config.RunnerParamsMongoBench | ||||||
| l *slog.Logger | ||||||
| } | ||||||
|
|
||||||
| // New creates a new runner with given parameters. | ||||||
| func New(params *config.RunnerParamsMongoBench, l *slog.Logger) (runner.Runner, error) { | ||||||
| return &mongoBench{ | ||||||
| p: params, | ||||||
| l: l, | ||||||
| }, nil | ||||||
| } | ||||||
|
|
||||||
| // parseFileNames parses the file names that store benchmark results. | ||||||
| // Each operation is stored in different files such as `benchmark_results_insert.csv`, | ||||||
| // `benchmark_results_update.csv`, `benchmark_results_delete.csv` and `benchmark_results_upsert.csv`. | ||||||
| func parseFileNames(r io.Reader) ([]string, error) { | ||||||
| var fileNames []string | ||||||
|
|
||||||
| scanner := bufio.NewScanner(r) | ||||||
| for scanner.Scan() { | ||||||
| line := scanner.Text() | ||||||
|
|
||||||
| if !strings.HasPrefix(line, "Benchmarking completed. Results saved to ") { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| // parse file name from the line such as `Benchmarking completed. Results saved to benchmark_results_delete.csv` | ||||||
| fileName := strings.TrimSpace(strings.TrimPrefix(line, "Benchmarking completed. Results saved to ")) | ||||||
| fileNames = append(fileNames, fileName) | ||||||
| } | ||||||
|
|
||||||
| if err := scanner.Err(); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| if len(fileNames) == 0 { | ||||||
| return nil, errors.New("no benchmark result files found") | ||||||
| } | ||||||
|
|
||||||
| return fileNames, nil | ||||||
| } | ||||||
|
|
||||||
| // readResult reads the file and gets the last measurement and parses it. | ||||||
| // The file contains measurements taken each second while the benchmark was running, | ||||||
| // the last measurement is parsed and returned. | ||||||
| func readResult(filePath string) (result map[string]float64, err error) { | ||||||
| var f *os.File | ||||||
|
|
||||||
| if f, err = os.Open(filePath); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| defer func() { | ||||||
| if e := f.Close(); e != nil && err == nil { | ||||||
| err = e | ||||||
| } | ||||||
| }() | ||||||
|
|
||||||
| // cannot use [csv.NewReader] because the file does not contain valid CSV, | ||||||
| // it contains 7 header fields while record lines contain 6 fields, | ||||||
| // so we parse it manually and assume the last field `mean_rate` is missing | ||||||
| s := bufio.NewScanner(f) | ||||||
|
|
||||||
| var lastLine string | ||||||
|
|
||||||
| for s.Scan() { | ||||||
| line := s.Text() | ||||||
|
|
||||||
| if strings.TrimSpace(line) != "" { | ||||||
| lastLine = line | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| if err = s.Err(); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| record := strings.Split(lastLine, ",") | ||||||
| if len(record) < 6 { | ||||||
| return nil, errors.New("insufficient fields") | ||||||
| } | ||||||
|
|
||||||
| var count, mean, m1Rate, m5Rate, m15Rate float64 | ||||||
|
|
||||||
| if count, err = strconv.ParseFloat(record[1], 64); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| if mean, err = strconv.ParseFloat(record[2], 64); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| if m1Rate, err = strconv.ParseFloat(record[3], 64); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| if m5Rate, err = strconv.ParseFloat(record[4], 64); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| if m15Rate, err = strconv.ParseFloat(record[5], 64); err != nil { | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| result = map[string]float64{ | ||||||
| "count": count, | ||||||
| "mean": mean, | ||||||
| "m1_rate": m1Rate, | ||||||
| "m5_rate": m5Rate, | ||||||
| "m15_rate": m15Rate, | ||||||
| } | ||||||
|
|
||||||
| return | ||||||
| } | ||||||
|
|
||||||
| // run runs given command in the given directory and returns parsed results. | ||||||
| func run(ctx context.Context, args []string, dir string) (map[string]config.TestResult, error) { | ||||||
| cmd := exec.CommandContext(ctx, args[0], args[1:]...) | ||||||
| cmd.Dir = dir | ||||||
| cmd.Stderr = os.Stderr | ||||||
|
|
||||||
| pipe, err := cmd.StdoutPipe() | ||||||
| if err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| defer pipe.Close() | ||||||
|
|
||||||
| if err = cmd.Start(); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| fileNames, err := parseFileNames(io.TeeReader(pipe, os.Stdout)) | ||||||
| if err != nil { | ||||||
| _ = cmd.Process.Kill() | ||||||
chilagrow marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| _ = cmd.Wait() | ||||||
|
|
||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| if err = cmd.Wait(); err != nil { | ||||||
| return nil, err | ||||||
| } | ||||||
|
|
||||||
| res := make(map[string]config.TestResult) | ||||||
|
|
||||||
| for _, fileName := range fileNames { | ||||||
| var m map[string]float64 | ||||||
|
|
||||||
| if m, err = readResult(filepath.Join("..", "projects", fileName)); err != nil { | ||||||
|
||||||
| if m, err = readResult(filepath.Join("..", "projects", fileName)); err != nil { | |
| if m, err = readResult(filepath.Join(dir, "projects", fileName)); err != nil { |
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.