Skip to content

Conversation

@timburks
Copy link
Contributor

This pares down @giteshk's benchmarks to a single set of CRUD tests on API resources that is hopefully easily extensible to other resources and scenarios. I'm not sure that we need to do this for every resource since the underlying operations don't vary much per resource. This alone seems enough to do some interesting comparisons of various hosting alternatives.

giteshk and others added 25 commits March 30, 2022 18:18
Added steps to run benchmark test on Github pull requests
Added benchmark tests for Listing Apis/ApiVersions/ApiSpecs/Artifacts
Additionally run benchmark tests on PRs only when the registry server code has been updated.
It will be added as a separate PR
this will be addressed in a seperate PR.
@codecov
Copy link

codecov bot commented Jun 25, 2022

Codecov Report

Merging #631 (881ea7d) into main (b8aac2d) will decrease coverage by 0.14%.
The diff coverage is 8.69%.

❗ Current head 881ea7d differs from pull request most recent head 928fdfd. Consider uploading reports for the commit 928fdfd to get more accurate results

@@            Coverage Diff             @@
##             main     #631      +/-   ##
==========================================
- Coverage   51.97%   51.83%   -0.15%     
==========================================
  Files          71       72       +1     
  Lines        6888     6911      +23     
==========================================
+ Hits         3580     3582       +2     
- Misses       2913     2934      +21     
  Partials      395      395              
Impacted Files Coverage Δ
tests/benchmark/benchmark_helpers.go 8.69% <8.69%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8aac2d...928fdfd. Read the comment docs.

@theganyo
Copy link
Member

Should we consider integrating benchmarking tracking into our builds? For example: https://github.com/marketplace/actions/continuous-benchmarking-for-go

@timburks
Copy link
Contributor Author

Should we consider integrating benchmarking tracking into our builds? For example: https://github.com/marketplace/actions/continuous-benchmarking-for-go

@theganyo sgtm! if it isn't a gating concern for this PR, let's just discuss it in an issue.

@theganyo
Copy link
Member

I attempted to run this locally and got errors...

➜  registry git:(timburks-benchmark-test) ✗ ./tests/benchmark/BENCH.sh
Error: rpc error: code = NotFound desc = "projects/bench" not found in database
Usage:
  registry rpc admin delete-project [flags]

Flags:
      --force              If set to true, any child resources will also be...
      --from_file string   Absolute path to JSON file containing request payload
  -h, --help               help for delete-project
      --name string        Required. The name of the project to delete.  Format:...

Global Flags:
  -j, --json      Print JSON output
  -v, --verbose   Print verbose output

rpc error: code = NotFound desc = "projects/bench" not found in database
{
  "name": "projects/bench",
  "createTime": "2022-06-27T15:39:55.060446Z",
  "updateTime": "2022-06-27T15:39:55.060446Z"
}
goos: darwin
goarch: arm64
pkg: github.com/apigee/registry/tests/benchmark
BenchmarkGetApi/GetApi-10         	--- FAIL: BenchmarkGetApi/GetApi-10
    benchmark_apis_test.go:95: CreateApi(test-1) returned unexpected error: rpc error: code = AlreadyExists desc = UNIQUE constraint failed: apis.key
--- FAIL: BenchmarkGetApi
BenchmarkListApis/ListApis-10     	--- FAIL: BenchmarkListApis/ListApis-10
    benchmark_apis_test.go:110: CreateApi(test-1) returned unexpected error: rpc error: code = AlreadyExists desc = UNIQUE constraint failed: apis.key
--- FAIL: BenchmarkListApis
BenchmarkCreateApi/CreateApi-10   	--- FAIL: BenchmarkCreateApi/CreateApi-10
    benchmark_apis_test.go:124: CreateApi(test-1) returned unexpected error: rpc error: code = AlreadyExists desc = UNIQUE constraint failed: apis.key
--- FAIL: BenchmarkCreateApi
BenchmarkUpdateApi/UpdateApi-10   	--- FAIL: BenchmarkUpdateApi/UpdateApi-10
    benchmark_apis_test.go:135: CreateApi(test-1) returned unexpected error: rpc error: code = AlreadyExists desc = UNIQUE constraint failed: apis.key
--- FAIL: BenchmarkUpdateApi
BenchmarkDeleteApi/DeleteApi-10   	       1	   2091834 ns/op
FAIL
exit status 1
FAIL	github.com/apigee/registry/tests/benchmark	0.403s
FAIL

@timburks
Copy link
Contributor Author

@theganyo it works for me... I was originally running on my Chromebook but just verified that it works on a MacBook (with a small change to line 21 of the script). How did you run this?

@timburks timburks requested a review from seaneganx June 28, 2022 01:05
@theganyo
Copy link
Member

./tests/benchmark/BENCH.sh needs +x perm set

@theganyo
Copy link
Member

Still getting the UNIQUE constraint failed: apis.key error above. It seems that wipeout isn't doing the job?

@timburks
Copy link
Contributor Author

timburks commented Jun 28, 2022

Well, I thought the problem was with wipeout but it seems instead that the function passed to Run() gets called multiple times without cleaning up after itself. Fixing...

(I was getting errors for test-1)

@theganyo
Copy link
Member

On another note re: schema. The wipeout code seems to make it clear we're not using foreign key constraints in the database? Manually maintaining DB integrity can be quite error prone... Shall I create an issue to address this?

@theganyo
Copy link
Member

This seems to work now. We should probably add a wipeout_test.go, though.

@timburks
Copy link
Contributor Author

@theganyo Agreed - after starting a wipeout_test.go, I'd prefer to add that in a separate PR because I expect a lot of discussion about the test structure.

@theganyo
Copy link
Member

nit: Can we add a README.md for the pkg dir?

@timburks
Copy link
Contributor Author

Done (added pkg/README.md)

var _err error

// Wipeout deletes all resources in a project using the specified number of parallel worker jobs.
func Wipeout(ctx context.Context, client connection.Client, projectid string, jobs int) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

projectID

Copy link
Contributor Author

@timburks timburks Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in c26a47f

)

// Set this global variable in calling code to run verbosely.
var Verbose bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we considered using flags or some other method for this config? I think this is the first use of config by setting a global var.

Also worth considering whether we need this at all, especially in the "minimal" initial benchmarks. We already have multiple logging levels that give control over the verbosity of output logs. If we want wipeout to be silent by default and optionally turned on, maybe we should just log at debug level instead of adding another dial for controlling log output.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll use a followup PR to change this to logging at Debug. How would we set that for a specific run of the test? (directly in code?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 19f552b

Artifact
)

type deleteResourceTask struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seems like a duplicate of deleteTask from the registry delete command. In #445 I suggested creating some reusable types for common tasks to avoid reinventing the wheel each time we want to do simple operations like creating/updating/deleting resources. Maybe now's the time?

The tasks can also be simpler by making them type-specific, which eliminates the "this should never happen" situation where we encounter an "unknown resource type" in these generic-esque tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partly addressed in #639

}

func getApi(b *testing.B, ctx context.Context, client connection.Client, apiId string) error {
b.Helper()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function doesn't actually fail/error/log using b, I don't think we gain anything from marking it as a helper (and can drop it entirely from the function).

Comment on lines +48 to +49
b.Logf("Unable to connect to registry server. Is it running?")
b.FailNow()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b.Fatalf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 3c841fc

return fmt.Sprintf("projects/%s/locations/global", projectID)
}

func setup(b *testing.B) (context.Context, connection.Client) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we return a context here? This seems like something we should accept from callers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reduced the boilerplate at the start of tests to a single call to setup(). Is there a style guide preference to not return a context from a function?

return ctx, client
}

func teardown(b *testing.B, ctx context.Context, client connection.Client) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use ctx context.Context, t *testing.T elsewhere, so maybe we should swap b and ctx here. In other Google projects we prefer that ordering too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8a8cd10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants