From: Brian Warner Date: Fri, 16 Nov 2007 05:53:55 +0000 (-0700) Subject: node.py: raise RLIMIT_NOFILE on bsd/cygwin to more than 256 X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/module-simplejson.encoder.html?a=commitdiff_plain;h=c6df66d7362405c6f83c9482014a97396871fb86;p=tahoe-lafs%2Ftahoe-lafs.git node.py: raise RLIMIT_NOFILE on bsd/cygwin to more than 256 --- diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 4979c68c..c9afa80d 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -1,5 +1,5 @@ -import datetime, os.path, re, types +import datetime, os.path, re, types, resource from base64 import b32decode, b32encode import twisted @@ -75,6 +75,52 @@ class Node(service.MultiService): " twisted: %s, zfec: %s" % (allmydata.__version__, foolscap.__version__, twisted.__version__, zfec.__version__,)) + self.increase_rlimits() + + def increase_rlimits(self): + # We'd like to raise our soft resource.RLIMIT_NOFILE, since certain + # systems (OS-X, probably solaris) start with a relatively low limit + # (256), and some unit tests want to open up more sockets than this. + # Most linux systems start with both hard and soft limits at 1024, + # which is plenty. + + # unfortunately the values to pass to setrlimit() vary widely from + # one system to another. OS-X reports (256, HUGE), but the real hard + # limit is 10240, and accepts (-1,-1) to mean raise it to the + # maximum. Cygwin reports (256, -1), then ignores a request of + # (-1,-1): instead you have to guess at the hard limit (it appears to + # be 3200), so using (3200,-1) seems to work. Linux reports a + # sensible (1024,1024), then rejects (-1,-1) as trying to raise the + # maximum limit, so you could set it to (1024,1024) but you might as + # well leave it alone. + + try: + current = resource.getrlimit(resource.RLIMIT_NOFILE)[0] + except AttributeError: + # we're probably missing RLIMIT_NOFILE, maybe this is windows + return + + if current >= 1024: + # good enough, leave it alone + return + + try: + # this one works on OS-X (bsd), and gives us 10240, but + # it doesn't work on linux (on which both the hard and + # soft limits are set to 1024 by default). + resource.setrlimit(resource.RLIMIT_NOFILE, (-1,-1)) + new = resource.getrlimit(resource.RLIMIT_NOFILE)[0] + if new == current: + # probably cygwin, which ignores -1. Use a real value. + resource.setrlimit(resource.RLIMIT_NOFILE, (3200,-1)) + + except ValueError: + self.log("unable to set RLIMIT_NOFILE: current value %s" + % (resource.getrlimit(resource.RLIMIT_NOFILE),)) + except: + # who knows what. It isn't very important, so log it and continue + log.err() + def get_config(self, name, mode="r", required=False): """Get the (string) contents of a config file, or None if the file