Added ApplicationSchedulingMode to KestrelServerOptions (#1759)

* Added ApplicationSchedulingMode to KestrelServerOptions
- Made default mode Default instead of ThreadPool
This commit is contained in:
David Fowler 2017-04-25 00:37:09 -07:00 committed by GitHub
parent a4def946a6
commit 566a587126
4 changed files with 34 additions and 9 deletions

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.Extensions.Logging;
namespace SampleApp
@ -45,7 +45,7 @@ namespace SampleApp
.UseKestrel(options =>
{
// Run callbacks on the transport thread
options.UseTransportThread = true;
options.ApplicationSchedulingMode = SchedulingMode.Inline;
options.Listen(IPAddress.Loopback, 5000, listenOptions =>
{

View File

@ -72,14 +72,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
var systemClock = new SystemClock();
var dateHeaderValueManager = new DateHeaderValueManager(systemClock);
IThreadPool threadPool;
if (serverOptions.UseTransportThread)
// TODO: This logic will eventually move into the IConnectionHandler<T> and off
// the service context once we get to https://github.com/aspnet/KestrelHttpServer/issues/1662
IThreadPool threadPool = null;
switch (serverOptions.ApplicationSchedulingMode)
{
threadPool = new InlineLoggingThreadPool(trace);
}
else
{
threadPool = new LoggingThreadPool(trace);
case SchedulingMode.Default:
case SchedulingMode.ThreadPool:
threadPool = new LoggingThreadPool(trace);
break;
case SchedulingMode.Inline:
threadPool = new InlineLoggingThreadPool(trace);
break;
default:
throw new NotSupportedException($"Unknown transport mode {serverOptions.ApplicationSchedulingMode}");
}
return new ServiceContext

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
namespace Microsoft.AspNetCore.Server.Kestrel.Core
{
@ -33,6 +34,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
/// </summary>
public bool UseTransportThread { get; set; }
/// <summary>
/// Gets or sets a value that determines how Kestrel should schedule user callbacks.
/// </summary>
/// <remarks>The default mode is <see cref="SchedulingMode.Default"/></remarks>
public SchedulingMode ApplicationSchedulingMode { get; set; } = SchedulingMode.Default;
/// <summary>
/// Enables the Listen options callback to resolve and use services registered by the application during startup.
/// Typically initialized by UseKestrel()"/>.

View File

@ -0,0 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions
{
public enum SchedulingMode
{
Default,
ThreadPool,
Inline
}
}