From b26cdb25c9cc2c89cd3522139f485b26df07e4cd Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Fri, 20 Mar 2020 17:09:59 +0100 Subject: [PATCH 1/2] add SocketEngineType.DefaultSockets --- test/web/ConsoleLineArgumentsParser.cs | 5 +- test/web/Program.cs | 64 +++++++++++++++----------- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/test/web/ConsoleLineArgumentsParser.cs b/test/web/ConsoleLineArgumentsParser.cs index bbb8af4..80aa382 100644 --- a/test/web/ConsoleLineArgumentsParser.cs +++ b/test/web/ConsoleLineArgumentsParser.cs @@ -11,7 +11,8 @@ public enum SocketEngineType EPoll, IOUring, IOUringTransport, - LinuxTransport + LinuxTransport, + DefaultSockets } public class CommandLineOptions @@ -19,7 +20,7 @@ public class CommandLineOptions // the booleans MUST be nullable, otherwise --arg false does not work... // see https://github.com/commandlineparser/commandline/issues/290 for more details - [Option('e', "engine", Required = false, Default = SocketEngineType.IOUring, HelpText = "EPoll/IOUring/IOUringTransport/LinuxTransport")] + [Option('e', "engine", Required = false, Default = SocketEngineType.IOUring, HelpText = "EPoll/IOUring/IOUringTransport/LinuxTransport/DefaultSockets")] public SocketEngineType SocketEngine { get; set; } [Option('t', "thread-count", Required = false, Default = 1, HelpText = "Thread Count, default value is 1")] diff --git a/test/web/Program.cs b/test/web/Program.cs index b89aea7..7caed38 100644 --- a/test/web/Program.cs +++ b/test/web/Program.cs @@ -34,38 +34,45 @@ public static IHostBuilder CreateHostBuilder(string[] args, CommandLineOptions c .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); - if (commandLineOptions.SocketEngine == SocketEngineType.IOUringTransport) + + switch (commandLineOptions.SocketEngine) { - webBuilder.ConfigureServices(serviceCollection => - serviceCollection.AddIoUringTransport(options => + case SocketEngineType.IOUringTransport: + webBuilder.ConfigureServices(serviceCollection => + serviceCollection.AddIoUringTransport(options => + { + options.ThreadCount = commandLineOptions.ThreadCount; + options.ApplicationSchedulingMode = commandLineOptions.ApplicationCodeIsNonBlocking.Value ? + PipeScheduler.Inline : PipeScheduler.ThreadPool; + })); + break; + case SocketEngineType.LinuxTransport: + webBuilder.UseLinuxTransport(options => { options.ThreadCount = commandLineOptions.ThreadCount; - options.ApplicationSchedulingMode = commandLineOptions.ApplicationCodeIsNonBlocking.Value ? - PipeScheduler.Inline : PipeScheduler.ThreadPool; - })); - } - else if (commandLineOptions.SocketEngine == SocketEngineType.LinuxTransport) - { - webBuilder.UseLinuxTransport(options => - { - options.ThreadCount = commandLineOptions.ThreadCount; - options.DeferSend = commandLineOptions.DeferSends.Value; - options.ApplicationSchedulingMode= commandLineOptions.ApplicationCodeIsNonBlocking.Value ? + options.DeferSend = commandLineOptions.DeferSends.Value; + options.ApplicationSchedulingMode= commandLineOptions.ApplicationCodeIsNonBlocking.Value ? PipeScheduler.Inline : PipeScheduler.ThreadPool; - }); - } - else - { - webBuilder.UseLinuxAsyncSockets(options => + }); + break; + case SocketEngineType.DefaultSockets: + webBuilder.UseSockets(options => { - options.DispatchContinuations = commandLineOptions.DispatchContinuations.Value; - options.DeferSends = commandLineOptions.DeferSends.Value; - options.DeferReceives = commandLineOptions.DeferReceives.Value; - options.DontAllocateMemoryForIdleConnections = commandLineOptions.DontAllocateMemoryForIdleConnections.Value; - options.OutputWriterScheduler = commandLineOptions.OutputWriterScheduler; - options.ApplicationCodeIsNonBlocking = commandLineOptions.ApplicationCodeIsNonBlocking.Value; - } - ); + options.IOQueueCount = commandLineOptions.ThreadCount; + }); + break; + default: + webBuilder.UseLinuxAsyncSockets(options => + { + options.DispatchContinuations = commandLineOptions.DispatchContinuations.Value; + options.DeferSends = commandLineOptions.DeferSends.Value; + options.DeferReceives = commandLineOptions.DeferReceives.Value; + options.DontAllocateMemoryForIdleConnections = commandLineOptions.DontAllocateMemoryForIdleConnections.Value; + options.OutputWriterScheduler = commandLineOptions.OutputWriterScheduler; + options.ApplicationCodeIsNonBlocking = commandLineOptions.ApplicationCodeIsNonBlocking.Value; + } + ); + break; } }); } @@ -84,7 +91,8 @@ private static AsyncEngine CreateAsyncEngine(CommandLineOptions commandLineOptio return new IOUringAsyncEngine(threadCount: commandLineOptions.ThreadCount, batchOnIOThread); case SocketEngineType.IOUringTransport: - case SocketEngineType.LinuxTransport: + case SocketEngineType.LinuxTransport: + case SocketEngineType.DefaultSockets: // Create EPollAsyncEngine with threadCount of zero. return new EPollAsyncEngine(threadCount: 0, useLinuxAio: false, From 51ef30976d98f6ad8b01238a1a82eb2825d991cd Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 21 Mar 2020 15:30:14 +0100 Subject: [PATCH 2/2] DefaultSockets -> DefaultTransport --- test/web/ConsoleLineArgumentsParser.cs | 4 ++-- test/web/Program.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/web/ConsoleLineArgumentsParser.cs b/test/web/ConsoleLineArgumentsParser.cs index 80aa382..b2836e0 100644 --- a/test/web/ConsoleLineArgumentsParser.cs +++ b/test/web/ConsoleLineArgumentsParser.cs @@ -12,7 +12,7 @@ public enum SocketEngineType IOUring, IOUringTransport, LinuxTransport, - DefaultSockets + DefaultTransport } public class CommandLineOptions @@ -20,7 +20,7 @@ public class CommandLineOptions // the booleans MUST be nullable, otherwise --arg false does not work... // see https://github.com/commandlineparser/commandline/issues/290 for more details - [Option('e', "engine", Required = false, Default = SocketEngineType.IOUring, HelpText = "EPoll/IOUring/IOUringTransport/LinuxTransport/DefaultSockets")] + [Option('e', "engine", Required = false, Default = SocketEngineType.IOUring, HelpText = "EPoll/IOUring/IOUringTransport/LinuxTransport/DefaultTransport")] public SocketEngineType SocketEngine { get; set; } [Option('t', "thread-count", Required = false, Default = 1, HelpText = "Thread Count, default value is 1")] diff --git a/test/web/Program.cs b/test/web/Program.cs index 7caed38..f6bf580 100644 --- a/test/web/Program.cs +++ b/test/web/Program.cs @@ -55,7 +55,7 @@ public static IHostBuilder CreateHostBuilder(string[] args, CommandLineOptions c PipeScheduler.Inline : PipeScheduler.ThreadPool; }); break; - case SocketEngineType.DefaultSockets: + case SocketEngineType.DefaultTransport: webBuilder.UseSockets(options => { options.IOQueueCount = commandLineOptions.ThreadCount; @@ -92,7 +92,7 @@ private static AsyncEngine CreateAsyncEngine(CommandLineOptions commandLineOptio batchOnIOThread); case SocketEngineType.IOUringTransport: case SocketEngineType.LinuxTransport: - case SocketEngineType.DefaultSockets: + case SocketEngineType.DefaultTransport: // Create EPollAsyncEngine with threadCount of zero. return new EPollAsyncEngine(threadCount: 0, useLinuxAio: false,