cubicweb/wsgi/server.py
author Philippe Pepiot <ph@itsalwaysdns.eu>
Tue, 31 Mar 2020 18:22:05 +0200
changeset 12966 6cd938c29ca3
parent 12001 89611a994572
permissions -rw-r--r--
[server] Make connection pooler configurable and set better default values Drop the configuration connections-pool-size and add new configurations options: * connections-pool-min-size. Set to 0 by default so we open connections only when needed. This avoid opening min-size*processes connections at startup, which is, it think, a good default. * connections-pool-max-size. Set to 0 (unlimited) by default, so we move the bottleneck to postgresql. * connections-idle-timeout. Set to 10 minutes. I don't have arguments about this except that this is the default in pgbouncer.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     1
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     3
#
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     4
# This file is part of CubicWeb.
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     5
#
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
     9
# any later version.
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    10
#
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    14
# details.
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    15
#
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    18
"""dummy wsgi server for CubicWeb web instances"""
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    19
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
    20
9287
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    21
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    22
from cubicweb.wsgi.handler import CubicWebWSGIApplication
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    23
from cubicweb import ConfigurationError
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    24
from wsgiref import simple_server
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    25
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    26
from logging import getLogger
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    27
LOGGER = getLogger('cubicweb')
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    28
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    29
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    30
def run(config):
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    31
    config.check_writeable_uid_directory(config.appdatahome)
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    32
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    33
    port = config['port'] or 8080
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    34
    interface = config['interface']
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    35
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    36
    app = CubicWebWSGIApplication(config)
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    37
    handler_cls = simple_server.WSGIRequestHandler
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    38
    httpd = simple_server.WSGIServer((interface, port), handler_cls)
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    39
    httpd.set_app(app)
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    40
    repo = app.appli.repo
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    41
    try:
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    42
        LOGGER.info('starting http server on %s', config['base-url'])
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    43
        httpd.serve_forever()
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    44
    finally:
e70c8c70e344 [wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
diff changeset
    45
        repo.shutdown()