ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.36k stars 1.64k forks source link

the problem of request consumption of gateway network #199

Closed jakey188 closed 6 years ago

jakey188 commented 6 years ago

I spent more network request time with the gateway。 http://localhost:8362/api/user/info?id=1 20ms - service address http://localhost:3164/api/user/info?id=1 200ms-ocelot gateway I've tried many times.I'm not very aware of the source code now, I will spend a certain amount of time studying ocelotsource code 。 I'm not sure the specific reason, but I hope you can restore this scene

chi7cha7rito commented 6 years ago

i have the same problem about this. i call the service address directly, it spent 73ms. but i call the service var ocelot gateway, it spent 11022ms. it's too slow.

chi7cha7rito commented 6 years ago

hi @jakey188, if you host the api by Kestrel not use iis. the problem will be solved.

jakey188 commented 6 years ago

@chi7cha7rito i not use iis. this should not be the key to the problem.

TomPallister commented 6 years ago

@jakey188

What logger level are you using and what type of logging? People often report performance problems with Ocelot and every time it is the logging in asp.net causing the problem.

Trying setting the logger level to Error or not using the console logger!

jakey188 commented 6 years ago

@TomPallister i setting the logger lever to error. the problem is still the same

TomPallister commented 6 years ago

@jakey188 please share your configuration.json. That might help us work out the problem.

jakey188 commented 6 years ago

@TomPallister configuration.json { "ReRoutes": [ { "DownstreamPathTemplate": "/api/user/{user}", "DownstreamScheme": "http", "DownstreamHost": "localhost", "DownstreamPort": 8362, "UpstreamPathTemplate": "/api/user/{user}", "UpstreamHttpMethod": [ "Get" ] } , { "DownstreamPathTemplate": "/api/product/{product}", "DownstreamScheme": "http", "DownstreamHost": "localhost", "DownstreamPort": 8330, "UpstreamPathTemplate": "/api/product/{product}", "UpstreamHttpMethod": [ "Get" ] } ], "GlobalConfiguration": { "ServiceDiscoveryProvider": { "Host": "localhost", "Port": 8500 } } } [Route("api/user")] public class UserController : Controller { [HttpGet("info")] public string Get(string id) { return "userInfo"; }

    [HttpGet("getById")]
    public string GetByUserId(string id)
    {
        return "user-getById";
    }
}

use ocelot 2.0.10

TomPallister commented 6 years ago

@jakey188 can you also paste your program.cs and Startup.cs

jakey188 commented 6 years ago

@TomPallister public class Program { public static void Main(string[] args) { //IWebHostBuilder builder = new WebHostBuilder(); //builder.ConfigureServices(s => { // s.AddSingleton(builder); //}); //builder.UseKestrel() // .UseContentRoot(Directory.GetCurrentDirectory()) // .UseIISIntegration() // .UseStartup(); //var host = builder.Build(); //host.Run(); BuildWebHost(args).Run(); }

    public static IWebHost BuildWebHost(string[] args)
    {
        IWebHostBuilder builder = WebHost.CreateDefaultBuilder(args);

        builder.UseStartup<Startup>()
            .ConfigureAppConfiguration((hostingContext, config) =>
        {
            config.AddJsonFile("configuration.json");
        })
        .ConfigureLogging((hostingContext, logging) =>
        {
            logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
            logging.AddConsole();
        });

        return builder.Build();
    }
}

public class Startup { // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) {

        services.AddOcelot()
            //.AddStoreOcelotConfigurationInConsul()
            .AddCacheManager((x) =>
            {
                x.WithMicrosoftLogging(log =>
                {
                    log.AddConsole(LogLevel.Error);
                })
                .WithDictionaryHandle();
            });

        services.AddMvc();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        app.UseOcelot().Wait();
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "api/{controller}/{action}/{id?}");
        });
    }
}

appsettings.json { "Logging": { "IncludeScopes": false, "Debug": { "LogLevel": { "Default": "Error" } }, "Console": { "LogLevel": { "Default": "Error" } } } }

single service user I don't think I need to share it

geffzhang commented 6 years ago

try to delete Console Logger @jakey188