mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 14:48:14 +08:00
Remove Ocelot specific Middleware to make Ocelot more compatible with kestrel middleware and get ready for YARP
This commit is contained in:
@ -1,31 +1,30 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Validators;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ocelot.Benchmarks
|
||||
{
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Validators;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.DownstreamRouteFinder.Middleware;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[SimpleJob(launchCount: 1, warmupCount: 2, targetCount: 5)]
|
||||
[Config(typeof(DownstreamRouteFinderMiddlewareBenchmarks))]
|
||||
public class DownstreamRouteFinderMiddlewareBenchmarks : ManualConfig
|
||||
{
|
||||
private DownstreamRouteFinderMiddleware _middleware;
|
||||
private DownstreamContext _downstreamContext;
|
||||
private OcelotRequestDelegate _next;
|
||||
private RequestDelegate _next;
|
||||
private HttpContext _httpContext;
|
||||
|
||||
public DownstreamRouteFinderMiddlewareBenchmarks()
|
||||
{
|
||||
@ -43,7 +42,6 @@ namespace Ocelot.Benchmarks
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var loggerFactory = services.GetService<IOcelotLoggerFactory>();
|
||||
var drpf = services.GetService<IDownstreamRouteProviderFactory>();
|
||||
var multiplexer = services.GetService<IMultiplexer>();
|
||||
|
||||
_next = async context =>
|
||||
{
|
||||
@ -51,22 +49,21 @@ namespace Ocelot.Benchmarks
|
||||
throw new Exception("BOOM");
|
||||
};
|
||||
|
||||
_middleware = new DownstreamRouteFinderMiddleware(_next, loggerFactory, drpf, multiplexer);
|
||||
_middleware = new DownstreamRouteFinderMiddleware(_next, loggerFactory, drpf);
|
||||
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.Request.Path = new PathString("/test");
|
||||
httpContext.Request.QueryString = new QueryString("?a=b");
|
||||
httpContext.Request.Headers.Add("Host", "most");
|
||||
httpContext.Items.SetIInternalConfiguration(new InternalConfiguration(new List<ReRoute>(), null, null, null, null, null, null, null, null));
|
||||
|
||||
_downstreamContext = new DownstreamContext(httpContext)
|
||||
{
|
||||
Configuration = new InternalConfiguration(new List<ReRoute>(), null, null, null, null, null, null, null, null)
|
||||
};
|
||||
_httpContext = httpContext;
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public async Task Baseline()
|
||||
{
|
||||
await _middleware.Invoke(_downstreamContext);
|
||||
await _middleware.Invoke(_httpContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +1,60 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Validators;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Errors.Middleware;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Middleware;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ocelot.Benchmarks
|
||||
{
|
||||
[SimpleJob(launchCount: 1, warmupCount: 2, targetCount: 5)]
|
||||
[Config(typeof(ExceptionHandlerMiddlewareBenchmarks))]
|
||||
public class ExceptionHandlerMiddlewareBenchmarks : ManualConfig
|
||||
{
|
||||
private ExceptionHandlerMiddleware _middleware;
|
||||
private DownstreamContext _downstreamContext;
|
||||
private OcelotRequestDelegate _next;
|
||||
|
||||
public ExceptionHandlerMiddlewareBenchmarks()
|
||||
{
|
||||
Add(StatisticColumn.AllStatistics);
|
||||
Add(MemoryDiagnoser.Default);
|
||||
Add(BaselineValidator.FailOnError);
|
||||
}
|
||||
|
||||
[GlobalSetup]
|
||||
public void SetUp()
|
||||
{
|
||||
var serviceCollection = new ServiceCollection();
|
||||
var config = new ConfigurationRoot(new List<IConfigurationProvider>());
|
||||
var builder = new OcelotBuilder(serviceCollection, config);
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var loggerFactory = services.GetService<IOcelotLoggerFactory>();
|
||||
var configRepo = services.GetService<IInternalConfigurationRepository>();
|
||||
var repo = services.GetService<IRequestScopedDataRepository>();
|
||||
namespace Ocelot.Benchmarks
|
||||
{
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Columns;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Validators;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Errors.Middleware;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[SimpleJob(launchCount: 1, warmupCount: 2, targetCount: 5)]
|
||||
[Config(typeof(ExceptionHandlerMiddlewareBenchmarks))]
|
||||
public class ExceptionHandlerMiddlewareBenchmarks : ManualConfig
|
||||
{
|
||||
private ExceptionHandlerMiddleware _middleware;
|
||||
private RequestDelegate _next;
|
||||
private HttpContext _httpContext;
|
||||
|
||||
public ExceptionHandlerMiddlewareBenchmarks()
|
||||
{
|
||||
Add(StatisticColumn.AllStatistics);
|
||||
Add(MemoryDiagnoser.Default);
|
||||
Add(BaselineValidator.FailOnError);
|
||||
}
|
||||
|
||||
[GlobalSetup]
|
||||
public void SetUp()
|
||||
{
|
||||
var serviceCollection = new ServiceCollection();
|
||||
var config = new ConfigurationRoot(new List<IConfigurationProvider>());
|
||||
var builder = new OcelotBuilder(serviceCollection, config);
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
var loggerFactory = services.GetService<IOcelotLoggerFactory>();
|
||||
var repo = services.GetService<IRequestScopedDataRepository>();
|
||||
|
||||
_next = async context =>
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new Exception("BOOM");
|
||||
};
|
||||
_middleware = new ExceptionHandlerMiddleware(_next, loggerFactory, configRepo, repo);
|
||||
_downstreamContext = new DownstreamContext(new DefaultHttpContext());
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public async Task Baseline()
|
||||
{
|
||||
await _middleware.Invoke(_downstreamContext);
|
||||
}
|
||||
}
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
throw new Exception("BOOM");
|
||||
};
|
||||
|
||||
_middleware = new ExceptionHandlerMiddleware(_next, loggerFactory, repo);
|
||||
_httpContext = new DefaultHttpContext();
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public async Task Baseline()
|
||||
{
|
||||
await _middleware.Invoke(_httpContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user