Commits

Anonymous committed d57c3c7

Database pool sizes are configurable now via environment variables. That should fix problems like #92.

Comments (0)

Files changed (3)

servers/zine.fcgi

 # path to the Zine application code.
 ZINE_LIB = '/usr/lib/zine'
 
+# these values can be use to override database pool settings.
+# see deployment guide for more details.
+POOL_SIZE = None
+POOL_RECYCLE = None
+POOL_TIMEOUT = None
 
+# ----------------------------------------------------------------------------
 # here you can further configure the fastcgi and wsgi app settings
-# but usually you don't have to touch them
+# but usually you don't have to touch them.
 import sys
+import os
+
 sys.path.insert(0, ZINE_LIB)
 
+for key in 'POOL_SIZE', 'POOL_RECYCLE', 'POOL_TIMEOUT':
+    value = locals().get(key)
+    if value is not None:
+        os.environ['ZINE_DATABASE_' + key] = value
+
 from zine import get_wsgi_app
 from flup.server.fcgi import WSGIServer
 app = get_wsgi_app(INSTANCE_FOLDER)

servers/zine.wsgi

 # path to the Zine application code.
 ZINE_LIB = '/usr/lib/zine'
 
+# these values can be use to override database pool settings.
+# see deployment guide for more details.
+POOL_SIZE = None
+POOL_RECYCLE = None
+POOL_TIMEOUT = None
+
 # here you can further configure the wsgi app settings but usually you don't
 # have to touch them
 import sys
+import os
 if ZINE_LIB not in sys.path:
     sys.path.insert(0, ZINE_LIB)
 
+for key in 'POOL_SIZE', 'POOL_RECYCLE', 'POOL_TIMEOUT':
+    value = locals().get(key)
+    if value is not None:
+        os.environ['ZINE_DATABASE_' + key] = value
+
 from zine import get_wsgi_app
 application = get_wsgi_app(INSTANCE_FOLDER)
     :license: BSD, see LICENSE for more details.
 """
 import re
+import os
 import sys
 import urlparse
 from os import path
         if info.drivername == 'mysql':
             info.query.setdefault('charset', 'utf8')
 
-    return sqlalchemy.create_engine(info, convert_unicode=True, echo=echo)
+    options = {'convert_unicode': True, 'echo': echo}
+
+    # alternative pool sizes / recycle settings and more.  These are
+    # interpreter wide and not from the config for the following reasons:
+    #
+    # - system administrators can set it independently from the webserver
+    #   configuration via SetEnv and friends.
+    # - this setting is deployment dependent should not affect a development
+    #   server for the same instance or a development shell
+    for key in 'pool_size', 'pool_recycle', 'pool_timeout':
+        value = os.environ.get('ZINE_DATABASE_' + key.upper())
+        if value is not None:
+            options[key] = int(value)
+
+    return sqlalchemy.create_engine(info, **options)
 
 
 def secure_database_uri(uri):