From dda654b474fe2962ac615924b4e078e5aae2ce49 Mon Sep 17 00:00:00 2001 From: "David E. Eisenstat" Date: Tue, 31 Oct 2006 14:57:52 +0000 Subject: [PATCH] Minimum 5% guaranteed allocation to prevent authors of resource brokers from shooting themselves in the foot. Renamed cf.py to conf_files.py. Various other tweaks. --- cf.py => conf_files.py | 0 database.py | 4 ++-- nm.py | 4 ++-- sliver_vs.py | 6 ++++-- tools.py | 4 ---- 5 files changed, 8 insertions(+), 10 deletions(-) rename cf.py => conf_files.py (100%) diff --git a/cf.py b/conf_files.py similarity index 100% rename from cf.py rename to conf_files.py diff --git a/database.py b/database.py index a49304f..cc1732d 100644 --- a/database.py +++ b/database.py @@ -116,10 +116,10 @@ def start(): while True: db_lock.acquire() while not dump_requested: db_cond.wait() - db_copy = tools.deepcopy(db) + db_pickle = cPickle.dumps(db, cPickle.HIGHEST_PROTOCOL) dump_requested = False db_lock.release() - try: tools.write_file(DB_FILE, lambda f: cPickle.dump(db_copy, f, -1)) + try: tools.write_file(DB_FILE, lambda f: f.write(db_pickle)) except: logger.log_exc() global db try: diff --git a/nm.py b/nm.py index cb76340..23a0d34 100644 --- a/nm.py +++ b/nm.py @@ -4,7 +4,7 @@ import optparse import time import xmlrpclib -import cf +import conf_files import logger import sm import tools @@ -38,7 +38,7 @@ def run(): return start_and_register_callback(sm) - start_and_register_callback(cf) + start_and_register_callback(conf_files) while True: try: GetSlivers() except: logger.log_exc() diff --git a/sliver_vs.py b/sliver_vs.py index 58798c5..4dad45d 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -93,7 +93,9 @@ class Sliver_VS(accounts.Account, vserver.VServer): self.init_disk_info() self.disk_usage_initialized = True vserver.VServer.set_disklimit(self, disk_max) - except OSError: logger.log_exc() + except OSError: + logger.log('%s: failed to set max disk usage' % self.name) + logger.log_exc() net_limits = (self.rspec['net_min'], self.rspec['net_max'], self.rspec['net2_min'], self.rspec['net2_max'], self.rspec['net_share']) logger.log('%s: setting net limits to %s bps' % (self.name, net_limits[:-1])) @@ -103,7 +105,7 @@ class Sliver_VS(accounts.Account, vserver.VServer): cpu_min = self.rspec['cpu_min'] cpu_share = self.rspec['cpu_share'] if self.rspec['enabled']: - if cpu_min > 0: + if cpu_min >= 50: # at least 5%: keep people from shooting themselves in the foot logger.log('%s: setting cpu share to %d%% guaranteed' % (self.name, cpu_min/10.0)) self.set_sched_config(cpu_min, vserver.SCHED_CPU_GUARANTEED) else: diff --git a/tools.py b/tools.py index 83f0327..0533570 100644 --- a/tools.py +++ b/tools.py @@ -36,10 +36,6 @@ def daemon(): devnull = os.open(os.devnull, os.O_RDWR) for fd in range(3): os.dup2(devnull, fd) -def deepcopy(obj): - """Return a deep copy of obj.""" - return cPickle.loads(cPickle.dumps(obj, -1)) - def fork_as(su, function, *args): """fork(), cd / to avoid keeping unused directories open, close all nonstandard file descriptors (to avoid capturing open sockets), fork() again (to avoid zombies) and call with arguments in the grandchild process. If is not None, set our group and user ids appropriately in the child process.""" child_pid = os.fork() -- 2.43.0