Skip to content

1.7 allocates an enormous amount of space from regex #15326

Closed

Description

@smarterclayton

Starting a large data set (32gb allocated, 4gb resident) in the api server causes about 7.5gb allocations of regexp.(*bitState).reset. The tree for that shows:

                                            1.56GB   100% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewParameter
         0     0% 23.08%     1.56GB  4.76%                | github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewBodyParameter
                                            1.14GB 72.82% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.PatternMatches
                                            0.40GB 25.67% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.InvalidKeysInMap
                                            0.02GB  1.51% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewSchema
----------------------------------------------------------+-------------
                                            0.23GB   100% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewDocument
         0     0% 23.08%     0.23GB  0.72%                | github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewDefinitions
                                            0.23GB   100% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewSchema
----------------------------------------------------------+-------------
                                            7.56GB   100% |   github.com/openshift/origin/vendor/k8s.io/apiserver/pkg/server/openapi.toProtoBinary
         0     0% 23.08%     7.56GB 23.08%                | github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewDocument
                                            7.32GB 96.90% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewPaths
                                            0.23GB  3.10% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewDefinitions
----------------------------------------------------------+-------------
                                            0.10GB   100% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewSchemaItem
         0     0% 23.08%     0.10GB  0.31%                | github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewFileSchema
                                            0.06GB 56.66% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.PatternMatches
                                            0.04GB 43.34% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.InvalidKeysInMap
----------------------------------------------------------+-------------
                                            1.08GB   100% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewNonBodyParameter
         0     0% 23.08%     1.08GB  3.29%                | github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewFormDataParameterSubSchema
                                            1.06GB 97.95% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.PatternMatches
                                            0.02GB  2.05% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.InvalidKeysInMap
----------------------------------------------------------+-------------
                                            1.12GB   100% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewNonBodyParameter
         0     0% 23.08%     1.12GB  3.41%                | github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewHeaderParameterSubSchema
                                            1.10GB 98.42% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.PatternMatches
                                            0.02GB  1.58% |   github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.InvalidKeysInMap

Is OpenAPI being invoked excessively from some place? Is this only dynamic discovery?

Activity

  1. added this to the milestone on Jul 20, 2017
  2. smarterclayton commented on Jul 28, 2017

    @smarterclayton
    ContributorAuthor

    This is one of the top reasons integration is slow. here's the allocations from a single integration run:

    $ time integration.test -test.run=TestBuildOverrideForcePull$
    real	0m14.528s
    user	0m38.061s
    sys	0m2.732s
    
    (pprof) top30
    26185370 of 30982552 total (84.52%)
    Dropped 1588 nodes (cum <= 154912)
    Showing top 30 nodes out of 306 (cum >= 229505)
          flat  flat%   sum%        cum   cum%
       3817116 12.32% 12.32%    3817116 12.32%  regexp.progMachine
       1777671  5.74% 18.06%    1826823  5.90%  regexp/syntax.(*parser).push
       1625949  5.25% 23.31%    2970332  9.59%  regexp/syntax.Compile
       1519623  4.90% 28.21%    1519623  4.90%  runtime.rawstringtmp
       1344262  4.34% 32.55%    1344262  4.34%  runtime.makemap
       1226530  3.96% 36.51%    1226530  3.96%  regexp/syntax.(*parser).newLiteral
       1133035  3.66% 40.17%    1133035  3.66%  regexp.(*bitState).reset
       1066409  3.44% 43.61%    1066409  3.44%  runtime.convT2E
       1049619  3.39% 46.99%    1633990  5.27%  github.com/openshift/origin/pkg/authorization/apis/authorization/v1.(*PolicyRule).Unmarshal
        840267  2.71% 49.71%     840267  2.71%  regexp/syntax.(*parser).collapse
        830478  2.68% 52.39%     830478  2.68%  github.com/openshift/origin/vendor/gopkg.in/yaml%2ev2.read
        769390  2.48% 54.87%     769390  2.48%  reflect.unsafe_New
        699053  2.26% 57.13%     699053  2.26%  regexp/syntax.(*Regexp).CapNames
        693998  2.24% 59.37%     726757  2.35%  runtime.mapassign
        690826  2.23% 61.60%    1344407  4.34%  regexp/syntax.(*compiler).compile
        688147  2.22% 63.82%     688147  2.22%  reflect.Value.Slice
        651919  2.10% 65.92%     651919  2.10%  regexp/syntax.(*compiler).rune
        646014  2.09% 68.01%    1301374  4.20%  regexp/syntax.(*parser).op
        641038  2.07% 70.08%    1365579  4.41%  github.com/openshift/origin/vendor/gopkg.in/yaml%2ev2.(*decoder).mappingSlice
        578907  1.87% 71.94%    6053346 19.54%  regexp.(*Regexp).doExecute
        573444  1.85% 73.80%    5159889 16.65%  regexp/syntax.Parse
        547275  1.77% 75.56%    9622609 31.06%  regexp.compile
        524288  1.69% 77.25%     524288  1.69%  regexp.(*Regexp).put
    

    @deads2k this is almost obscene, and is mostly what is causing your problems with slow integration.

  3. smarterclayton commented on Jul 28, 2017

    @smarterclayton
    ContributorAuthor

    I ran the parallel integration suite. It took 1400 seconds on an 8 hyper thread mac and ALL cores were at 100% the entire time. I.e. about 3 core hours to run the suite.

    CPU for the test above (across 3 runs to get better metrics):

    (pprof) top50
    45.80s of 104.93s total (43.65%)
    Dropped 1824 nodes (cum <= 0.52s)
    Showing top 50 nodes out of 409 (cum >= 8.80s)
          flat  flat%   sum%        cum   cum%
             0     0%     0%     94.68s 90.23%  runtime.goexit
         0.32s   0.3%   0.3%     71.15s 67.81%  runtime.systemstack
             0     0%   0.3%     45.82s 43.67%  runtime.gcBgMarkWorker
         1.14s  1.09%  1.39%     42.51s 40.51%  runtime.gcDrain
             0     0%  1.39%     42.50s 40.50%  runtime.gcBgMarkWorker.func2
        20.71s 19.74% 21.13%     30.69s 29.25%  runtime.scanobject
             0     0% 21.13%     24.02s 22.89%  github.com/openshift/origin/vendor/k8s.io/apiserver/pkg/server/openapi.(*OpenAPIService).UpdateSpec
             0     0% 21.13%     21.67s 20.65%  github.com/openshift/origin/vendor/k8s.io/apiserver/pkg/server/openapi.toProtoBinary
         1.43s  1.36% 22.49%     19.80s 18.87%  runtime.mallocgc
             0     0% 22.49%     19.78s 18.85%  github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewDocument
             0     0% 22.49%     19.02s 18.13%  github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewPaths
             0     0% 22.49%     18.80s 17.92%  github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewPathItem
         0.03s 0.029% 22.52%     18.33s 17.47%  github.com/openshift/origin/vendor/github.com/googleapis/gnostic/compiler.PatternMatches
             0     0% 22.52%     18.27s 17.41%  github.com/openshift/origin/test/integration.setupBuildPodAdmissionTest
             0     0% 22.52%     18.23s 17.37%  github.com/openshift/origin/test/integration.setupBuildOverridesAdmissionTest
             0     0% 22.52%     18.22s 17.36%  github.com/openshift/origin/test/util/server.StartConfiguredMasterWithOptions
             0     0% 22.52%     18.21s 17.35%  github.com/openshift/origin/pkg/cmd/server/start.(*Master).Start
             0     0% 22.52%     18.21s 17.35%  github.com/openshift/origin/test/util/server.StartConfiguredMaster
             0     0% 22.52%     18.19s 17.34%  github.com/openshift/origin/test/integration.TestBuildOverrideForcePull
         0.03s 0.029% 22.55%     18.16s 17.31%  regexp.Match
             0     0% 22.55%     18.15s 17.30%  testing.tRunner
             0     0% 22.55%     17.42s 16.60%  github.com/openshift/origin/pkg/cmd/server/start.StartAPI
             0     0% 22.55%     17.11s 16.31%  github.com/openshift/origin/vendor/k8s.io/kube-aggregator/pkg/apiserver.(*APIAggregator).updateOpenAPISpec
         0.04s 0.038% 22.59%     14.96s 14.26%  regexp.(*Regexp).doExecute
         0.02s 0.019% 22.61%     14.93s 14.23%  regexp.(*Regexp).doMatch
             0     0% 22.61%     14.84s 14.14%  regexp.(*Regexp).Match
         0.03s 0.029% 22.63%     14.53s 13.85%  github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewParametersItem
             0     0% 22.63%     14.50s 13.82%  github.com/openshift/origin/pkg/cmd/server/origin.(*MasterConfig).Run
             0     0% 22.63%     14.36s 13.69%  github.com/openshift/origin/vendor/github.com/googleapis/gnostic/OpenAPIv2.NewParameter
         0.07s 0.067% 22.70%     14.03s 13.37%  runtime.makeslice
         0.01s 0.0095% 22.71%     13.38s 12.75%  regexp.(*machine).backtrack
             0     0% 22.71%     12.45s 11.87%  github.com/openshift/origin/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil
             0     0% 22.71%     12.43s 11.85%  github.com/openshift/origin/vendor/k8s.io/apimachinery/pkg/util/wait.Until
             0     0% 22.71%     12.41s 11.83%  github.com/openshift/origin/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1
         0.02s 0.019% 22.73%     12.38s 11.80%  regexp.(*bitState).reset
    
  4. smarterclayton commented on Jul 28, 2017

    @smarterclayton
    ContributorAuthor

    The 20% of CPU we are spending in openapi is creating 30% of our garbage, which probably accounts for the bulk of the 40% of our time we spend in GC. So I'm comfortable with saying that the problem that has to be fixed is to make this disappear - we do that, and you should cut the integration test runtime to a third of what it is today.

    I'd like to get a volunteer to go fix this.

  5. deads2k commented on Jul 28, 2017

    @deads2k
    Contributor

    Opened kubernetes/kubernetes#49776 upstream and I'll see what workarounds we have in our 3.7.

  6. added a commit that references this issue on Jul 28, 2017
  7. smarterclayton commented on Jul 31, 2017

    @smarterclayton
    ContributorAuthor

    So... sometime around 2-3pm today we went back to taking 2h10m. I don't know that it's #15537, but it's the only thing I know of that touched integration today.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions