Skip to content

queue-proxy is huge #9957

Open
Open

Description

@mattmoor

/area API
/area autoscale
/area networking

What version of Knative?

HEAD

Expected Behavior

queue-proxy is trivially small.

Actual Behavior

As of this morning, queue-proxy is ~55.7MB.

Steps to Reproduce the Problem

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build ./cmd/queue
ls -l queue

Going to self-assign, but feel free to jump in and party on this with me.
/assign

Activity

  1. added
    kind/bug
    on Oct 27, 2020
  2. mattmoor commented on Oct 27, 2020

    @mattmoor
    ContributorAuthor

    Goal: eliminate queue-proxy dependency on k8s.io/client-go/kubernetes

    Two offenders:

    1. k8s.io/client-go/informers is pulled in via the informed watcher in knative.dev/pkg/configmap (unused in queue-proxy): Splitting configmap package to avoid heavy dependencies pkg#1851
    2. k8s.io/client-go/kubernetes is pulled in directly via knative.dev/pkg/metrics for the stackdriver exporter to fetch secrets.

    Pulling in the above PR and commenting the kubeClient references in knative.dev/pkg/metrics yields a binary size of 42,193,344 (32% reduction in size).

  3. mattmoor commented on Oct 27, 2020

    @mattmoor
    ContributorAuthor

    Goal: eliminate queue-proxy dependency on contrib.go.opencensus.io/exporter/stackdriver

    Two offenders:

    1. knative.dev/pkg/metrics
    2. knative.dev/pkg/tracing

    Commenting out the stackdriver logic in these packages further reduces the queue-proxy binary size to 35,560,653 (another 18% reduction).

    cc @evankanderson

  4. vagababov commented on Oct 27, 2020

    @vagababov
    Contributor

    In my build opencensus also seems to pull 793066 T github.com/aws/aws-sdk-go/aws/endpoints.init which with other aws stuff is another meg.

  5. mattmoor commented on Oct 27, 2020

    @mattmoor
    ContributorAuthor

    FWIW, that's likely included in my figures, unless it is transitively pulled in through other things. I'm measuring the overall binary size once a particular cut point in the dependency graph has been snipped.

  6. mattmoor commented on Oct 27, 2020

    @mattmoor
    ContributorAuthor

    Shouldn't effect the code pages, but @tcnghia also found that if we use:

    GOFLAGS=-ldflags="-s -w"
    

    It drops things another ~10MB (on top of what I measured above). Seems like the lowest hanging fruit yet.

    https://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/

  7. mattmoor commented on Oct 30, 2020

    @mattmoor
    ContributorAuthor

    @evankanderson do you want to link to or summarize your thoughts on timeline to cut this dependency?

  8. github-actions commented on Jan 29, 2021

    @github-actions

    This issue is stale because it has been open for 90 days with no
    activity. It will automatically close after 30 more days of
    inactivity. Reopen the issue with /reopen. Mark the issue as
    fresh by adding the comment /remove-lifecycle stale.

  9. 30 remaining items

  10. modified the milestones: v1.3.0, v1.4.0 on Mar 10, 2022
  11. modified the milestones: v1.4.0, v1.5.0 on May 10, 2022
  12. modified the milestones: v1.5.0, v1.6.0 on May 27, 2022
  13. modified the milestones: v1.6.0, Icebox on Jul 14, 2022
  14. qiming-007 commented on Jan 2, 2024

    @qiming-007

    Maaaybe something like Rust, ... it does sound kind of fun as a proof of concept.

    I mean envoy is written in c++ and has survived ok so.. rust may not be so bad (and it has worked well for linkerd)! I started a repo at http://github.com/julz/roo-proxy a while ago to experiment a bit (without much progress yet, tho!). One thing I'd really like to try is to see how much of QP we could reimplement as a wasm plug-in for envoy-- that way we could reuse all of the great work and optimisations and features in envoy and (for people who already have mesh) avoid needing a second sidecar at all.

    Anyway, totally ack that there's a maintainability trade-off here, just this may be a case where it's warranted (empirically QP is very expensive for what it does), and rust is pretty ok.

    @julz
    The topic is a little old, but I am wondering are there any findings/update for reimplementing QP as a wasm plug-in in envoy? The idea is promising even now.

  15. dprotaso commented on Jul 11, 2025

    @dprotaso
    Member

    So there are still gains to be made by dropping k8s.io/api/core/v1 & k8s.io/api/apps/v1` but it requires a lot of reshuffling of packages and types.

    Specifically the list is

    1. Split up the networking/pkg to separate packages networking#670

    2. Move autoscaler/metric.Stat to it's own package so it doesn't pull in any autoscaling APIs

    3. Don't consume corev1.Probe in the queue proxy - but create a copy of it

    4. Move knative.dev/configmap.Parse methods to their own package - no corev1 dep

    5. Drop corev1 usage in knative.dev/pkg/metrics

      1. drop use of corev1.Secret
      2. drop use of corev1.ConfigMap - move ConfigMapWatcher to it's own package
    6. Drop corev1 usage in knative.dev/pkg/tracing

      1. drop use of corev1.ConfigMap

    I tested changes 1-3 and removed tracing and metrics in order to see what the floor of completing 4-6 would be - that resulted in a queue-proxy binary size of 15MB.

    There's probably a gain to be had when we removed it's copy of prometheus libs - ie. #11126

    Following up on this - as part of moving to OTel libs the new knative.dev/pkg/observability should be segmented so it doesn't rely on k8s deps.

    One thing I recently discovered is that using certain libraries is preventing dead code elimination by the compiler - https://github.com/aarzilli/whydeadcode/

    I'm wondering if this is really the root cause to the bloat (eg. k8s deps should be pruned by the compiler)

  16. mattmoor commented on Jul 11, 2025

    @mattmoor
    ContributorAuthor

    Yeah, @dims did a bunch of work on this recently in K8s itself.

  17. dprotaso commented on Jul 11, 2025

    @dprotaso
    Member

    There's a few places to dive into - one is building with grpcnotrace -

    https://github.com/grpc/grpc-go/blob/3d0cb79a78772b48422793c579395ba7da64d6f3/trace_notrace.go#L22-L25

    After that text/template, go-cmp are other sources.

    $ go build -tags grpcnotrace -ldflags=-dumpdep ./cmd/queue |& whydeadcode 
    text/template.(*state).evalField reachable from:
             text/template.(*state).evalFieldChain
             text/template.(*state).evalCommand
             text/template.(*state).evalPipeline
             text/template.(*state).walk
             text/template.(*Template).execute
             knative.dev/serving/pkg/http.(*RequestLogHandler).write
             knative.dev/serving/pkg/http.(*RequestLogHandler).ServeHTTP.func1
             knative.dev/serving/pkg/http.(*RequestLogHandler).ServeHTTP
             type:*knative.dev/serving/pkg/http.RequestLogHandler
             type:knative.dev/serving/pkg/http.RequestLogHandler
             knative.dev/serving/pkg/http.NewRequestLogHandler
             knative.dev/serving/pkg/queue/sharedmain.requestLogHandler
             knative.dev/serving/pkg/queue/sharedmain.mainHandler
             knative.dev/serving/pkg/queue/sharedmain.Main
             main.main
             runtime.main_main·f
             runtime.main
             runtime.mainPC
             runtime.rt0_go
             _rt0_arm64_darwin
             main
             _
    
    github.com/modern-go/reflect2.(*safeType).MethodByName reachable from:
             type:*github.com/modern-go/reflect2.safeType
             type:github.com/modern-go/reflect2.safeType
             github.com/modern-go/reflect2.(*frozenConfig).wrapType
             github.com/modern-go/reflect2.(*frozenConfig).Type2
             github.com/modern-go/reflect2.(*frozenConfig).TypeOf
             github.com/json-iterator/go.init
             github.com/json-iterator/go..inittask
             go:main.inittasks
             _
    
    github.com/google/go-cmp/cmp/internal/value.appendTypeName reachable from:
             github.com/google/go-cmp/cmp.pathStep.String
             type:github.com/google/go-cmp/cmp.pathStep
             github.com/google/go-cmp/cmp.rootStep
             github.com/google/go-cmp/cmp.Equal
             knative.dev/pkg/kmp.SafeEqual
             knative.dev/pkg/kmp.CompareSetFields
             knative.dev/pkg/apis.CheckDisallowedFields
             knative.dev/networking/pkg/apis/networking.ValidateNamespacedObjectReference
             knative.dev/networking/pkg/apis/networking/v1alpha1.(*ServerlessServiceSpec).Validate
             type:*knative.dev/networking/pkg/apis/networking/v1alpha1.ServerlessServiceSpec
             type:knative.dev/networking/pkg/apis/networking/v1alpha1.ServerlessServiceSpec
             type:knative.dev/networking/pkg/apis/networking/v1alpha1.ServerlessService
             knative.dev/networking/pkg/apis/networking/v1alpha1.addKnownTypes
             knative.dev/networking/pkg/apis/networking/v1alpha1.addKnownTypes·f
             knative.dev/networking/pkg/apis/networking/v1alpha1.init
             knative.dev/networking/pkg/apis/networking/v1alpha1..inittask
             go:main.inittasks
             _
    
  18. dprotaso commented on Jul 11, 2025

    @dprotaso
    Member

    For templating we could explore https://github.com/valyala/fasttemplate

    I'm also wondering if go-cmp can be 'quarantined' using a sync.Once or something

  19. evankanderson commented on Jul 11, 2025

    @evankanderson
    Member

    I'm slightly concerned about the leakage of go-cmp via knative.dev/pkg/apis.CheckDisallowedFields -- is this something that we could simplify using go templates (e.g. should request and maskedRequest be the same type)?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/APIarea/autoscalearea/networkingkind/buglifecycle/frozentriage/accepted

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions