def add_broks_to_queue(self, broks): statsmgr.incr('core.broker.broks.in', len(broks), 'queue') # Ok now put in queue broks to be managed by # internal modules with self.broks_lock: self.broks.extend(broks) self.external_module_broks.extend(broks)
def f_wrapper(): t0 = time.time() args_time = aqu_lock_time = calling_time = json_time = 0 need_lock = getattr(f, 'need_lock', True) # Warning : put the bottle.response set inside the wrapper # because outside it will break bottle d = {} method = getattr(f, 'method', 'get').lower() for aname in args: v = None if method == 'post': v = bottle.request.forms.get(aname, None) # Post args are zlibed and cPickled if v is not None: v = zlib.decompress(v) v = cPickle.loads(v) elif method == 'get': v = bottle.request.GET.get(aname, None) if v is None: # Maybe we got a default value? default_args = self.registered_fun_defaults.get( fname, {}) if not aname in default_args: raise Exception('Missing argument %s' % aname) v = default_args[aname] d[aname] = v t1 = time.time() args_time = t1 - t0 if need_lock: logger.debug("HTTP: calling lock for %s", fname) lock.acquire() t2 = time.time() aqu_lock_time = t2 - t1 try: ret = f(**d) # Always call the lock release if need finally: # Ok now we can release the lock if need_lock: lock.release() t3 = time.time() calling_time = t3 - t2 encode = getattr(f, 'encode', 'json').lower() j = json.dumps(ret) t4 = time.time() json_time = t4 - t3 global_time = t4 - t0 logger.debug( "Debug perf: %s [args:%s] [aqu_lock:%s] [calling:%s] [json:%s] [global:%s]", fname, args_time, aqu_lock_time, calling_time, json_time, global_time) lst = [('args', args_time), ('aqulock', aqu_lock_time), ('calling', calling_time), ('json', json_time), ('global', global_time)] # increase the stats timers for (k, _t) in lst: statsmgr.incr('http.%s.%s' % (fname, k), _t) return j
def f_wrapper(): t0 = time.time() args_time = aqu_lock_time = calling_time = json_time = 0 need_lock = getattr(f, 'need_lock', True) # Warning : put the bottle.response set inside the wrapper # because outside it will break bottle d = {} method = getattr(f, 'method', 'get').lower() for aname in args: v = None if method == 'post': v = bottle.request.forms.get(aname, None) # Post args are zlibed and cPickled if v is not None: v = zlib.decompress(v) v = cPickle.loads(v) elif method == 'get': v = bottle.request.GET.get(aname, None) if v is None: # Maybe we got a default value? default_args = self.registered_fun_defaults.get(fname, {}) if not aname in default_args: raise Exception('Missing argument %s' % aname) v = default_args[aname] d[aname] = v t1 = time.time() args_time = t1 - t0 if need_lock: logger.debug("HTTP: calling lock for %s", fname) lock.acquire() t2 = time.time() aqu_lock_time = t2 - t1 try: ret = f(**d) # Always call the lock release if need finally: # Ok now we can release the lock if need_lock: lock.release() t3 = time.time() calling_time = t3 - t2 encode = getattr(f, 'encode', 'json').lower() j = json.dumps(ret) t4 = time.time() json_time = t4 - t3 global_time = t4 - t0 logger.debug("Debug perf: %s [args:%s] [aqu_lock:%s] [calling:%s] [json:%s] [global:%s]", fname, args_time, aqu_lock_time, calling_time, json_time, global_time ) lst = [('args',args_time), ('aqulock',aqu_lock_time), ('calling',calling_time), ('json',json_time), ('global',global_time)] # increase the stats timers for (k, _t) in lst: statsmgr.incr('http.%s.%s' % (fname, k), _t) return j
def pynag_con_init(self, id, type='scheduler'): _t = time.time() r = self.do_pynag_con_init(id, type) statsmgr.incr('con-init.%s' % type, time.time() - _t) return r
if self.new_conf: self.setup_new_conf() # Maybe the last loop we raised some broks internally # we should integrate them in broks self.interger_internal_broks() # Also reap broks sent from the arbiters self.interger_arbiter_broks() # Main job, go get broks in our distants daemons types = ['scheduler', 'poller', 'reactionner', 'receiver'] for _type in types: _t = time.time() # And from schedulers self.get_new_broks(type=_type) statsmgr.incr('get-new-broks.%s' % _type, time.time() - _t) # Sort the brok list by id self.broks.sort(sort_by_ids) # and for external queues # REF: doc/broker-modules.png (3) # We put to external queues broks that was not already send t0 = time.time() # We are sending broks as a big list, more efficient than one by one queues = self.modules_manager.get_external_to_queues() to_send = [b for b in self.broks if getattr(b, 'need_send_to_ext', True)] for q in queues: q.put(to_send)
if self.new_conf: self.setup_new_conf() # Maybe the last loop we raised some broks internally # we should integrate them in broks self.interger_internal_broks() # Also reap broks sent from the arbiters self.interger_arbiter_broks() # Main job, go get broks in our distants daemons types = ['scheduler', 'poller', 'reactionner', 'receiver'] for _type in types: _t = time.time() # And from schedulers self.get_new_broks(type=_type) statsmgr.incr('get-new-broks.%s' % _type, time.time() - _t) # Sort the brok list by id self.broks.sort(sort_by_ids) # and for external queues # REF: doc/broker-modules.png (3) # We put to external queues broks that was not already send t0 = time.time() # We are sending broks as a big list, more efficient than one by one ext_modules = self.modules_manager.get_external_instances() to_send = [ b for b in self.broks if getattr(b, 'need_send_to_ext', True) ] # Send our pack to all external modules to_q queue so they can get the wole packet