Burgyn / MMLib.SwaggerForOcelot

This repo contains swagger extension for ocelot.
MIT License
351 stars 93 forks source link

IApplicationBuilder.UseSwaggerForOcelotUI takes a lot memory #255

Closed mastak-in-ua closed 1 year ago

mastak-in-ua commented 1 year ago

Ocelot requires up to 500Mb additional memory to start a service with UseSwaggerForOcelotUI enabled.

How to reproduce:

  1. run service without UseSwaggerForOcelotUI enabled: image
  2. run service with UseSwaggerForOcelotUI enabled: image

swagger.json file size 688Kb, about 300 operations routes.json 56Kb with routes to 2 external services and gateway inself

If use ocelot routes with a service with only a few operations ( 10 operations ) it takes much less memory: image

So it looks like more operations in target service - ocelot will take and keep more memory.

Burgyn commented 1 year ago

Hi @mastak-in-ua

Yes, you're right. This is the scenario with a certain post of operations and dependencies in the schema. The problem is how I parse JSON and try to match ocelot routing to swagger endpoints.

Unfortunately I don't have the time to fix this right now. If you feel like it, you can try it. It's all done in the SwaggerJsonTransformer class.

If not then you can try use the parameter RemoveUnusedComponentsFromScheme

"SwaggerEndPoints": [
{
  "Key": "projects",
  "RemoveUnusedComponentsFromScheme": false,
  "Config": [
    {
      "Name": "Projects API",
      "Version": "v1",
      "Service": {
        "Name": "projects",
        "Path": "/swagger/v1/swagger.json"
      }
    }
  ]
}
github-actions[bot] commented 1 year ago

Closing after 8 days of waiting for the additional info requested.