Commit 21145521 authored by Jérome Perrin's avatar Jérome Perrin Committed by Aurel

zopewsgi: configure threads count and large_file_threshold with argparse

On Zope4 these settings are no longer in zope.conf
parent c01de1ad
...@@ -84,7 +84,7 @@ class TransLogger(object): ...@@ -84,7 +84,7 @@ class TransLogger(object):
self.logger.info(message) self.logger.info(message)
def app_wrapper(large_file_threshold=10<<20, webdav_ports=()): def app_wrapper(large_file_threshold, webdav_ports):
try: try:
from Products.DeadlockDebugger.dumper import dump_threads, dump_url from Products.DeadlockDebugger.dumper import dump_threads, dump_url
except Exception: except Exception:
...@@ -163,6 +163,7 @@ def createServer(application, logger, **kw): ...@@ -163,6 +163,7 @@ def createServer(application, logger, **kw):
return server return server
def runwsgi(): def runwsgi():
type_registry = ZConfig.datatypes.Registry()
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--event-log-file', help='Event log file') parser.add_argument('--event-log-file', help='Event log file')
parser.add_argument('--access-log-file', help='Access log file') parser.add_argument('--access-log-file', help='Access log file')
...@@ -171,12 +172,19 @@ def runwsgi(): ...@@ -171,12 +172,19 @@ def runwsgi():
parser.add_argument('address', help='<ip>:<port>') parser.add_argument('address', help='<ip>:<port>')
parser.add_argument('zope_conf', help='path to zope.conf') parser.add_argument('zope_conf', help='path to zope.conf')
parser.add_argument('--timerserver-interval', help='Interval for timerserver', type=float) parser.add_argument('--timerserver-interval', help='Interval for timerserver', type=float)
parser.add_argument('--threads', help='Number of threads', default=4, type=int)
parser.add_argument(
'--large-file-threshold',
help='Requests bigger than this size in bytes get saved into a temporary file '
'instead of being read completely into memory.',
type=type_registry.get('byte-size'),
default=type_registry.get('byte-size')("10MB"))
args = parser.parse_args() args = parser.parse_args()
startup = os.path.dirname(Zope2.Startup.__file__) startup = os.path.dirname(Zope2.Startup.__file__)
if os.path.isfile(os.path.join(startup, 'wsgischema.xml')): if os.path.isfile(os.path.join(startup, 'wsgischema.xml')):
schema = ZConfig.loadSchema(os.path.join(startup, 'wsgischema.xml')) schema = ZConfig.loadSchema(os.path.join(startup, 'wsgischema.xml'))
else: # BBB else: # BBB Zope2
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml')) schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml'))
conf, _ = ZConfig.loadConfig(schema, args.zope_conf) conf, _ = ZConfig.loadConfig(schema, args.zope_conf)
...@@ -238,11 +246,11 @@ def runwsgi(): ...@@ -238,11 +246,11 @@ def runwsgi():
port = int(port) port = int(port)
createServer( createServer(
app_wrapper( app_wrapper(
large_file_threshold=getattr(conf, 'large_file_threshold', None), large_file_threshold=args.large_file_threshold,
webdav_ports=[port] if args.webdav else ()), webdav_ports=[port] if args.webdav else ()),
listen=args.address, listen=args.address,
logger=access_log_logger, logger=access_log_logger,
threads=getattr(conf, 'zserver_threads', 4), threads=args.threads,
asyncore_use_poll=True, asyncore_use_poll=True,
# Prevent waitress from adding its own Via and Server response headers. # Prevent waitress from adding its own Via and Server response headers.
ident=None, ident=None,
......
...@@ -183,8 +183,12 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase): ...@@ -183,8 +183,12 @@ class ProcessingNodeTestCase(ZopeTestCase.TestCase):
logger = logging.getLogger("access") logger = logging.getLogger("access")
logger.addHandler(logging.FileHandler(log)) logger.addHandler(logging.FileHandler(log))
logger.propagate = False logger.propagate = False
hs = createServer(app_wrapper(webdav_ports=webdav_ports), hs = createServer(
logger, sockets=sockets) app_wrapper(
large_file_threshold=10<<20,
webdav_ports=webdav_ports),
logger,
sockets=sockets)
ProcessingNodeTestCase._server_address = hs.addr ProcessingNodeTestCase._server_address = hs.addr
t = Thread(target=hs.run) t = Thread(target=hs.run)
t.setDaemon(1) t.setDaemon(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment