<commit_before>from __future__ import absolute_import

from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
import os
from dallinger.config import get_config
import logging

logger = logging.getLogger(__file__)

WORKER_CLASS = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker'


def when_ready(arbiter):
    # Signal to parent process that server has started
    logger.warn('Ready.')


class StandaloneServer(Application):
    loglevels = ["debug", "info", "warning", "error", "critical"]

    def __init__(self):
        """__init__ method
        Load the base config and assign some core attributes.
        """
        self.usage = None
        self.cfg = None
        self.callable = None
        self.prog = None
        self.logger = None

        self.load_user_config()
        self.do_load_config()

    @property
    def port(self):
        """Heroku sets the port its running on as an environment variable"""
        return os.environ.get('PORT')

    def init(self, *args):
        """init method
        Takes our custom options from self.options and creates a config
        dict which specifies custom settings.
        """
        cfg = {}
        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                cfg[k.lower()] = v
        return cfg

    def load(self):
        """Return our application to be run."""
        app = util.import_app("dallinger.experiment_server.sockets:app")
        if self.options.get('mode') == 'debug':
            app.debug = True
        return app

    def load_user_config(self):
        config = get_config()
        workers = config.get("threads")
        if workers == "auto":
            workers = str(multiprocessing.cpu_count() * 2 + 1)

        host = config.get("host")
        mode = config.get("mode")
        bind_address = "{}:{}".format(host, self.port)
        self.options = {<commit_msg>Reduce default gunicorn worker count.<commit_after>from __future__ import absolute_import

from gunicorn.app.base import Application
from gunicorn import util
import multiprocessing
import os
from dallinger.config import get_config
import logging

logger = logging.getLogger(__file__)

WORKER_CLASS = 'geventwebsocket.gunicorn.workers.GeventWebSocketWorker'


def when_ready(arbiter):
    # Signal to parent process that server has started
    logger.warn('Ready.')


class StandaloneServer(Application):
    loglevels = ["debug", "info", "warning", "error", "critical"]

    def __init__(self):
        """__init__ method
        Load the base config and assign some core attributes.
        """
        self.usage = None
        self.cfg = None
        self.callable = None
        self.prog = None
        self.logger = None

        self.load_user_config()
        self.do_load_config()

    @property
    def port(self):
        """Heroku sets the port its running on as an environment variable"""
        return os.environ.get('PORT')

    def init(self, *args):
        """init method
        Takes our custom options from self.options and creates a config
        dict which specifies custom settings.
        """
        cfg = {}
        for k, v in self.options.items():
            if k.lower() in self.cfg.settings and v is not None:
                cfg[k.lower()] = v
        return cfg

    def load(self):
        """Return our application to be run."""
        app = util.import_app("dallinger.experiment_server.sockets:app")
        if self.options.get('mode') == 'debug':
            app.debug = True
        return app

    def load_user_config(self):
        config = get_config()
        workers = config.get("threads")
        if workers == "auto":
            workers = str(multiprocessing.cpu_count() + 1)

        host = config.get("host")
        mode = config.get("mode")
        bind_address = "{}:{}".format(host, self.port)
        self.options = {
{'fraction_non_alphanumeric': 0.10518292682926829, 'fraction_numerical': 0.0007621951219512195, 'mean_word_length': 2.4234782608695653, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '4725447', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1080, 'n_words': 329}