← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/turnip:raise-open-file-limit into turnip:master

 

Colin Watson has proposed merging ~cjwatson/turnip:raise-open-file-limit into turnip:master.

Commit message:
Raise open files limit to 4096

Occasional libgit2 leaks mean that 1024 tends to be insufficient quite
quickly.  This should give us a bit more headroom.

This should ideally be done in the gunicorn service configuration
instead, but the charm doesn't currently make this very customisable.
This is good enough for now.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/turnip/+git/turnip/+merge/322968
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/turnip:raise-open-file-limit into turnip:master.
diff --git a/turnip/api/__init__.py b/turnip/api/__init__.py
index e1d7225..b9b83cf 100644
--- a/turnip/api/__init__.py
+++ b/turnip/api/__init__.py
@@ -1,12 +1,19 @@
 # Copyright 2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-"""Main entry point
-"""
+"""Main entry point."""
+
+import resource
+
 from pyramid.config import Configurator
 
 
 def main(global_config, **settings):
+    # Allow slack for lots of open pack files.
+    _, hard_nofile = resource.getrlimit(resource.RLIMIT_NOFILE)
+    resource.setrlimit(
+        resource.RLIMIT_NOFILE, (min(4096, hard_nofile), hard_nofile))
+
     config = Configurator(settings=settings)
     config.include("cornice")
     config.scan("turnip.api.views")