Skip to content
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

Add benchmark that lists artifacts under each resource type. #1068

Merged
merged 3 commits into from
Mar 3, 2023

Conversation

timburks
Copy link
Contributor

@timburks timburks commented Mar 2, 2023

This adds a benchmark test that lists artifacts under different resource types.

I've casually observed that listing artifacts under specs takes longer than listing artifacts under APIs, and guessed that this might be related to revision support. The test here creates N=100 APIs, each with one version, spec, and deployment, and with three artifacts ("a", "b", and "c") under each resource. Three revisions of each spec and deployment are created with artifacts only associated with the last ones created. Then we list all of the "b" artifacts under each resource type.

Running locally with Postgres on my Chromebook, I don't see much difference in listing times:

BenchmarkListArtifacts
BenchmarkListArtifacts/ListApiArtifacts
BenchmarkListArtifacts/ListApiArtifacts-8                     75          14497073 ns/op
BenchmarkListArtifacts/ListVersionArtifacts
BenchmarkListArtifacts/ListVersionArtifacts-8                 51          20340059 ns/op
BenchmarkListArtifacts/ListSpecArtifacts
BenchmarkListArtifacts/ListSpecArtifacts-8                    50          22871343 ns/op
BenchmarkListArtifacts/ListDeploymentArtifacts
BenchmarkListArtifacts/ListDeploymentArtifacts-8              54          19693489 ns/op

If I increase the number of APIs to N=1000, a distinction is more clear:

BenchmarkListArtifacts
BenchmarkListArtifacts/ListApiArtifacts
BenchmarkListArtifacts/ListApiArtifacts-8                      3         418735575 ns/op
BenchmarkListArtifacts/ListVersionArtifacts
BenchmarkListArtifacts/ListVersionArtifacts-8                  2         551807149 ns/op
BenchmarkListArtifacts/ListSpecArtifacts
BenchmarkListArtifacts/ListSpecArtifacts-8                     2         807084090 ns/op
BenchmarkListArtifacts/ListDeploymentArtifacts
BenchmarkListArtifacts/ListDeploymentArtifacts-8               2         743311222 ns/op

This doesn't seem to be as severe as it subjectively seemed to me, but this is local and my observations were running with a remote database.

Setup time dominates the runtime of these tests, so this PR keeps N=100.

@timburks timburks requested a review from theganyo March 2, 2023 23:31
@@ -41,7 +41,7 @@ func getApi(b *testing.B, ctx context.Context, client connection.RegistryClient,

func listApis(b *testing.B, ctx context.Context, client connection.RegistryClient) error {
b.Helper()
it := client.ListApis(ctx, &rpc.ListApisRequest{Parent: root()})
it := client.ListApis(ctx, &rpc.ListApisRequest{Parent: root().String() + "/locations/global"})
Copy link
Member

Choose a reason for hiding this comment

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

Apropos of nothing, every time I see this omnipresent "/locations/global" constant in our code it sends me down a rabbit hole of wondering how we could eliminate it globally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should do something in the names package. #470?

@timburks
Copy link
Contributor Author

timburks commented Mar 2, 2023

Here's a pretty interesting result from benchmarking a networked test server running with Postgres (N = 100):

BenchmarkListArtifacts/ListApiArtifacts-16         	      38	  30631349 ns/op
BenchmarkListArtifacts/ListVersionArtifacts-16     	      30	  37002730 ns/op
BenchmarkListArtifacts/ListSpecArtifacts-16        	       1	2729463578 ns/op
BenchmarkListArtifacts/ListDeploymentArtifacts-16  	       8	 125910637 ns/op

registry rpc admin get-status returns this for the vcs.revision of my build: 891333a8615e69ee3a2c6043116b78e5ba70f5b7, so it's a fairly fresh server.

The server has a couple of big projects, total database usage is summarized here:

$ registry rpc admin get-storage --json
{
  "description": "postgres",
  "collections": [
    {
      "name": "apis",
      "count": "5894"
    },
    {
      "name": "artifacts",
      "count": "34448"
    },
    {
      "name": "blobs",
      "count": "47555"
    },
    {
      "name": "deployment_revision_tags"
    },
    {
      "name": "deployments"
    },
    {
      "name": "projects",
      "count": "6"
    },
    {
      "name": "spec_revision_tags",
      "count": "1"
    },
    {
      "name": "specs",
      "count": "13107"
    },
    {
      "name": "versions",
      "count": "9211"
    }
  ]
}

I think the difference in runtimes of the artifacts under specs and deployments is probably because there are a lot of specs (>13000) and no deployments apart from whatever we create for the benchmark.

Here are the results of the same benchmarks with N = 1000:

BenchmarkListArtifacts/ListApiArtifacts-16         	       3	  435709811 ns/op
BenchmarkListArtifacts/ListVersionArtifacts-16     	       3	  455032674 ns/op
BenchmarkListArtifacts/ListSpecArtifacts-16        	       1	72584223258 ns/op
BenchmarkListArtifacts/ListDeploymentArtifacts-16  	       1	17589723714 ns/op

@timburks
Copy link
Contributor Author

timburks commented Mar 3, 2023

#1069

@timburks timburks force-pushed the benchmark-artifact-lists branch from 1c3128d to f1d89d9 Compare March 3, 2023 04:24
@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Merging #1068 (e5ae700) into main (3248ec6) will not change coverage.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##             main    #1068   +/-   ##
=======================================
  Coverage   68.01%   68.01%           
=======================================
  Files         147      147           
  Lines       11982    11982           
=======================================
  Hits         8149     8149           
  Misses       3133     3133           
  Partials      700      700           
Impacted Files Coverage Δ
tests/benchmark/benchmark_helpers.go 12.50% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@timburks timburks merged commit a405b01 into apigee:main Mar 3, 2023
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.

2 participants