wundergraph / cosmo

The open-source solution to building, maintaining, and collaborating on GraphQL Federation at Scale. The alternative to Apollo Studio and GraphOS.
https://cosmo-docs.wundergraph.com/
Apache License 2.0
659 stars 93 forks source link

IntrospectionQuery is causing huge memory consumption after the latest updates #959

Closed flymedllva closed 1 month ago

flymedllva commented 1 month ago

Component(s)

router

Component version

0119c2d656674c07dde45372298a7b6ab625e70f

wgc version

0.58.5

controlplane version

-

router version

0119c2d656674c07dde45372298a7b6ab625e70f

What happened?

Description

After one of the recent Cosmo updates, there is an abnormal increase in memory consumption when calling IntrospectionQuery (e.g. in the Playground refresh button).

Our schema (config.json), from which we get this result, weighs 13.7M. On older versions of cosmo we didn't have this problem.

Occurs after executing err = t.loader.LoadGraphQLResponseData(ctx, response, t.resolvable) in resolve.go (wundergraph/graphql-go-tools/v2@v2.0.0-rc.63)

Steps to Reproduce

Expected Result

Consume the normal amount of memory for this request)

Actual Result

Brutal memory consumption)

https://github.com/user-attachments/assets/4793a6be-76a3-4647-91e3-667967081b5d

Environment information

Environment

OS: (e.g., "Ubuntu 20.04") macOS / Linux Package Manager: npm Compiler(if manually compiled): go version go1.22.3 darwin/arm64

Router configuration

version: "1"

# General router options
graph:
  name: "production"
  token: ""

log_level: "info"
listen_addr: "localhost:3002"
playground_enabled: true
introspection_enabled: true
json_log: true
shutdown_delay: 15s
grace_period: 20s
poll_interval: 10s
health_check_path: "/health"
readiness_check_path: "/health/ready"
liveness_check_path: "/health/live"
router_config_path: "config.json"

cors:
  allow_origins: ["*"]
  allow_methods:
    - HEAD
    - GET
    - POST
  allow_headers:
    - Origin
    - Content-Length
    - Content-Type
  allow_credentials: true
  max_age_minutes: 5m

# Config for custom modules   
# See "https://cosmo-docs.wundergraph.com/router/custom-modules" for more information   
modules:
  myModule:
    # Arbitrary values, unmarshalled by the module
    value: 1

Router execution config

No response

Log output

No response

Additional context

No response

github-actions[bot] commented 1 month ago

WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.

jensneuse commented 1 month ago

Does the same behavior happen when you make a introspection query from e.g. curl while disabling brotli? We've got a suspicion that the brotli Middleware is responsible, which gets usually activated by browsers.

flymedllva commented 1 month ago

OK, 50MB – router@0.95.1 Memory running out, 10GB+ – router@0.95.2

Video of work using router@0.95.2 https://github.com/user-attachments/assets/ab57f1c7-f7ea-4a73-b801-e0cc927ec53e

I haven't figured out how to disable brotli on this version, hint? I couldn't find it in the doc. I can cut it in the code if you tell me where)

flymedllva commented 1 month ago

Could it be?

https://github.com/wundergraph/graphql-go-tools/pull/845/files

flymedllva commented 1 month ago

8d7f20a7f43c29a1a0e80510afb6e7c318fcd080 in cosmo increased memory consumption in this scenario

flymedllva commented 1 month ago

Just in case. That PR https://github.com/wundergraph/cosmo/pull/968 didn't solve the problem

Since it seems to be consuming memory in graphql-go-tools/v2

StarpTech commented 1 month ago

Hi @flymedllva please retry the latest release. We did couple of optimizations. We will take a deeper look if it is still reproducible. Thank you.

flymedllva commented 1 month ago

Hi @StarpTech, I tried router@0.99.1, the result is the same

Please note my recent posts

https://github.com/user-attachments/assets/26cd1c75-6b7c-4d78-ba00-88937fdd8665

StarpTech commented 1 month ago

Hi, thanks for the test. Could you attach your router config here or send me via dustin@wundergraph.com? Thank you!

YassineElbouchaibi commented 1 month ago

Same on my side, 4gb has always be enough memory but since a few releases introspection has been failing and pods restarting: image The spikes timestamps match with introspection queries.

StarpTech commented 1 month ago

@flymedllva please send me your router config. https://cosmo-docs.wundergraph.com/cli/router/fetch

flymedllva commented 1 month ago

Hi @StarpTech, sent it to your email dustin@wundergraph.com

flymedllva commented 1 month ago

@jensneuse @StarpTech

I tried https://github.com/wundergraph/cosmo/pull/986, no introspection problems on it, thanks!