<commit_before>// 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;
using System.Collections.Generic;
using Microsoft.AspNet.Server.Features;
using Microsoft.AspNet.Server.Kestrel.Filter;
using Microsoft.Extensions.Configuration;

namespace Microsoft.AspNet.Server.Kestrel
{
    public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature
    {
        public KestrelServerInformation(IConfiguration configuration)
        {
            Addresses = GetAddresses(configuration);
            ThreadCount = GetThreadCount(configuration);
            NoDelay = true;
        }

        public ICollection<string> Addresses { get; }

        public int ThreadCount { get; set; }

        public bool NoDelay { get; set; }

        public IConnectionFilter ConnectionFilter { get; set; }

        private static ICollection<string> GetAddresses(IConfiguration configuration)
        {
            var addresses = new List<string>();

            var urls = configuration["server.urls"];

            if (!string.IsNullOrEmpty(urls))
            {
                addresses.AddRange(urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            }

            return addresses;
        }

        private static int GetThreadCount(IConfiguration configuration)
        {
            // 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).
            // Can be user overriden using IKestrelServerInformation.ThreadCount
            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;
        }
    }
}<commit_msg>Made ThreadCount configurable<commit_after>// 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;
using System.Collections.Generic;
using Microsoft.AspNet.Server.Features;
using Microsoft.AspNet.Server.Kestrel.Filter;
using Microsoft.Extensions.Configuration;

namespace Microsoft.AspNet.Server.Kestrel
{
    public class KestrelServerInformation : IKestrelServerInformation, IServerAddressesFeature
    {
        public KestrelServerInformation(IConfiguration configuration)
        {
            Addresses = GetAddresses(configuration);
            ThreadCount = GetThreadCount(configuration);
            NoDelay = true;
        }

        public ICollection<string> Addresses { get; }

        public int ThreadCount { get; set; }

        public bool NoDelay { get; set; }

        public IConnectionFilter ConnectionFilter { get; set; }

        private static ICollection<string> GetAddresses(IConfiguration configuration)
        {
            var addresses = new List<string>();

            var urls = configuration["server.urls"];

            if (!string.IsNullOrEmpty(urls))
            {
                addresses.AddRange(urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            }

            return addresses;
        }

        private static int GetThreadCount(IConfiguration configuration)
        {
            var threadCountString = configuration["server.threadCount"];

            int threadCount;
            if (string.IsNullOrEmpty(threadCountString) || !int.TryParse(threadCountString, out threadCount))
            {
                // 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).
                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;
        }
    }
}
{'fraction_non_alphanumeric': 0.0726407284768212, 'fraction_numerical': 0.004966887417218543, 'mean_word_length': 1.9907178217821782, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4554599', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1113, 'n_words': 353}