// 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.
using System;
namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
{
///
/// Provides programmatic configuration of Libuv transport features.
///
public class LibuvTransportOptions
{
///
/// The number of libuv I/O threads used to process requests.
///
///
/// Defaults to half of rounded down and clamped between 1 and 16.
///
public int ThreadCount { get; set; } = ProcessorThreadCount;
// TODO: Move all shutdown timeout logic back into core project.
///
/// The amount of time after the server begins shutting down before connections will be forcefully closed.
/// Kestrel will wait for the duration of the timeout for any ongoing request processing to complete before
/// terminating the connection. No new connections or requests will be accepted during this time.
///
///
/// Defaults to 5 seconds.
///
public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5);
private static int ProcessorThreadCount
{
get
{
// Actual core count would be a better number
// rather than logical cores which includes hyper-threaded cores.
// Divide by 2 for hyper-threading, and good defaults (still need threads to do webserving).
var threadCount = Environment.ProcessorCount >> 1;
if (threadCount < 1)
{
// Ensure shifted value is at least one
return 1;
}
if (threadCount > 16)
{
// Receive Side Scaling RSS Processor count currently maxes out at 16
// would be better to check the NIC's current hardware queues; but xplat...
return 16;
}
return threadCount;
}
}
}
}