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

Build OpenAPI Definitions per group instead of per resource #68576

Merged
merged 2 commits into from
Nov 15, 2018

Conversation

jennybuckley
Copy link

@jennybuckley jennybuckley commented Sep 12, 2018

What this PR does / why we need it:
Addresses inefficiencies in the implementation of #63893

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of fixing #66368
Not sure where the 40 seconds comes from in the referenced bug, but this PR reduced startup time of kube apiserver by ~20% on my computer

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 12, 2018
@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Sep 12, 2018
@jennybuckley jennybuckley changed the title Build OpenAPI Definitions per groupversion instead of per resource Build OpenAPI Definitions per group instead of per resource Sep 12, 2018
@jennybuckley
Copy link
Author

/sig api-machinery
/kind bug

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. kind/bug Categorizes issue or PR as related to a bug. area/apiserver and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Sep 12, 2018
@jennybuckley
Copy link
Author

/retest

@fedebongio
Copy link
Contributor

/assign @mbohlool

return gvkToSchema, nil
}

func getCanonicalTypeName(model interface{}) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a copy from somewhere?

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

can you reuse this please? these two copy can get out of sync. move them to somewhere common if necessary.

Copy link
Author

Choose a reason for hiding this comment

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

I can, but it is in the kube-openapi repo, so it would mean changing it there first, and then vendoring it back in

Copy link
Author

Choose a reason for hiding this comment

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

What if I just put a TODO for this, and also make the PR to kube-openapi repo

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding todo and sending PR to kube-openapu repo looks good to me. Send a followup PR after the openapi PR got merged. Thanks.

@jennybuckley
Copy link
Author

I just ran some pprof analysis on startup of a basic API server with no extensions, before and after this change.

Before this change, a total of ~16.7 million objects were allocated within the first 50 seconds of startup.
After this change, only ~12.0 million objects were allocated in the same time frame.

@smarterclayton
Copy link
Contributor

Hrm, was hoping for a more dramatic reduction. Where were the bulk of the remaining allocations coming from under a cumulative sort?

@jennybuckley
Copy link
Author

jennybuckley commented Sep 20, 2018

@smarterclayton About 5.5 million were coming from the openapi endpoint handler, which creates just one full openapi spec and serves it, and this change doesn't touch that code. I think the openapi spec might just take that many objects to create.

      flat  flat%   sum%        cum   cum%
         0     0%     0%    6332343 52.70%  k8s.io/kubernetes/cmd/kube-apiserver/app.CreateServerChain
         0     0%     0%    6154823 51.23%  k8s.io/kubernetes/cmd/kube-apiserver/app.Run
         0     0%     0%    5834452 48.56%  k8s.io/kubernetes/cmd/kube-apiserver/app.NewAPIServerCommand.func1
         0     0%     0%    5631494 46.87%  k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).execute
         0     0%     0%    5576641 46.41%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/handler.(*OpenAPIService).UpdateSpec
         0     0%     0%    5318267 44.26%  k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).ExecuteC
         0     0%     0%    5301052 44.12%  k8s.io/kubernetes/vendor/k8s.io/kube-openapi/pkg/handler.toProtoBinary
         0     0%     0%    5085712 42.33%  k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).Execute
         0     0%     0%    4835898 40.25%  main.main
         0     0%     0%    4733475 39.40%  runtime.main

@smarterclayton
Copy link
Contributor

smarterclayton commented Sep 20, 2018 via email

@jennybuckley
Copy link
Author

Going to hold off on this until #69316 merges, since it also vendors in some unrelated kube-openapi changes

@roycaihw roycaihw mentioned this pull request Oct 31, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 1, 2018
@jennybuckley
Copy link
Author

Since #70260 merged, this doesn't need to vendor in kube-openapi anymore. Should be good to merge now, uses the exported function from kube-openapi
cc @mbohlool

@jennybuckley
Copy link
Author

/retest

if err != nil {
return gvkToSchema, err
}
sampleObject := reflect.Indirect(reflect.ValueOf(sampleObjectPtr)).Interface()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you probably don't need this. it should work if you pass sampleObjectPtr.

@mbohlool
Copy link
Contributor

mbohlool commented Nov 6, 2018

only one nit comment. otherwise look good.

/lgtm

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Nov 6, 2018
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 10, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 13, 2018
@jennybuckley
Copy link
Author

Rebased

@lavalamp
Copy link
Member

/lgtm
/approve
/milestone v1.13

@k8s-ci-robot k8s-ci-robot added this to the v1.13 milestone Nov 14, 2018
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 14, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jennybuckley, lavalamp

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 14, 2018
@lavalamp lavalamp added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Nov 14, 2018
@apelisse apelisse added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 14, 2018
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@apelisse
Copy link
Member

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-ci-robot k8s-ci-robot merged commit b7e2980 into kubernetes:master Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/code-generation cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants