<commit_before># Author: <NAME>
# Date: 28 Sep 2009
#
# This code patches mongrel to use a thread pool instead of creating a new thread
# for every request. It also traps SIGTERM to close all connections
# Changed method run to accept an extra parameter to set thread pool size
#


require File.expand_path(File.dirname(__FILE__)+'/threadpool')


module Mongrel
    class HttpServer

        def run(_pool_size = 100)
            trap("TERM") { stop } # trap "kill"

            @thread_pool = ThreadTools::ThreadPool.new(_pool_size, @workers)

            BasicSocket.do_not_reverse_lookup = true

            configure_socket_options

            if defined?($tcp_defer_accept_opts) and $tcp_defer_accept_opts
                @socket.setsockopt(*$tcp_defer_accept_opts) rescue nil
            end

            @acceptor = Thread.new do
                begin
                    while true
                        begin
                            client = @socket.accept

                            if defined?($tcp_cork_opts) and $tcp_cork_opts
                                client.setsockopt(*$tcp_cork_opts) rescue nil
                            end

                            worker_list = @workers.list

                            if worker_list.length >= @num_processors
                                STDERR.puts "Server overloaded with #{worker_list.length} processors (#@num_processors max). Dropping connection."
                                client.close rescue nil
                                reap_dead_workers("max processors")
                            else
                                thread = @thread_pool.spawn(client) {|c| process_client(c) }
                                thread[:started_on] = Time.now
                                sleep @throttle if @throttle > 0<commit_msg>removed useless var assignment<commit_after># Author: <NAME>
# Date: 28 Sep 2009
#
# This code patches mongrel to use a thread pool instead of creating a new thread
# for every request. It also traps SIGTERM to close all connections
# Changed method run to accept an extra parameter to set thread pool size
#


require File.expand_path(File.dirname(__FILE__)+'/threadpool')


module Mongrel
    class HttpServer

        def run(_pool_size = 100)
            trap("TERM") { stop } # trap "kill"

            @thread_pool = ThreadTools::ThreadPool.new(_pool_size, @workers)

            BasicSocket.do_not_reverse_lookup = true

            configure_socket_options

            if defined?($tcp_defer_accept_opts) and $tcp_defer_accept_opts
                @socket.setsockopt(*$tcp_defer_accept_opts) rescue nil
            end

            @acceptor = Thread.new do
                begin
                    while true
                        begin
                            client = @socket.accept

                            if defined?($tcp_cork_opts) and $tcp_cork_opts
                                client.setsockopt(*$tcp_cork_opts) rescue nil
                            end

                            worker_list = @workers.list

                            if worker_list.length >= @num_processors
                                STDERR.puts "Server overloaded with #{worker_list.length} processors (#@num_processors max). Dropping connection."
                                client.close rescue nil
                                reap_dead_workers("max processors")
                            else
                                @thread_pool.spawn(client) do |c|
                                    Thread.current[:started_on] = Time.now
                                    process_client(c)
                                end
                                sleep @throttle if @throttle > 0
{'fraction_non_alphanumeric': 0.06316916488222699, 'fraction_numerical': 0.0053533190578158455, 'mean_word_length': 1.4109677419354838, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4717178', 'n_tokens_mistral': 956, 'n_tokens_neox': 876, 'n_words': 247}