def start(cls): try: profile_dir = options.get('relaax_metrics_server/profile_dir') if profile_dir is not None: profiling.set_handlers([profiling.FileHandler(os.path.join( profile_dir, 'metrics.txt'))]) profiling.enable(True) logger.info("Starting metrics server on %s:%d" % options.bind) # keep the server or else GC will stop it server = metrics_bridge_server.MetricsBridgeServer(options.bind, MetricsHandler()) server.start() events = multiprocessing.Queue() signal.signal(signal.SIGINT, cls.exit_server) signal.signal(signal.SIGTERM, cls.exit_server) cls.stopped_server = False while not cls.stopped_server: #time.sleep(1) try: msg = events.get(timeout=1) except Empty: pass except: break except KeyboardInterrupt: # swallow KeyboardInterrupt pass except: raise
def test_global_wrap(self): assert len(self.mh.records) == 0 self.method() assert len(self.mh.records) == 0 profiling.enable(True) self.method() assert len(self.mh.records) == 1 self.method() assert len(self.mh.records) == 2 profiling.enable(False) self.method() assert len(self.mh.records) == 2 assert self.mh.records[0]['dur'] >= 10000
def test_wrap(self): assert len(self.mh.records) == 0 self.method2() assert len(self.mh.records) == 0 profiling.enable(True) self.method2() assert len(self.mh.records) == 1 self.method2() assert len(self.mh.records) == 2 profiling.enable(False) self.method2() assert len(self.mh.records) == 2 assert self.mh.records[0]['cat'] == 'tests.profiling_test' assert self.mh.records[0]['name'] == 'TestProfiling.method2' assert self.mh.records[0]['dur'] >= 10000
def start(cls): try: profile_dir = options.get('relaax_parameter_server/profile_dir') if profile_dir is not None: profiling.set_handlers([ profiling.FileHandler(os.path.join(profile_dir, 'ps.txt')) ]) profiling.enable(True) log.info("Starting parameter server on %s:%d" % options.bind) log.info("Expecting metrics server on %s:%d" % options.metrics_server) ps_factory = CallOnce(cls.init) # keep the server or else GC will stop it server = ps_bridge_server.PsBridgeServer(options.bind, ps_factory) server.start() ps = ps_factory() watch = cls.make_watch(ps) speedm = Speedometer(ps) events = multiprocessing.Queue() signal.signal(signal.SIGINT, cls.exit_server) signal.signal(signal.SIGTERM, cls.exit_server) cls.stopped_server = False if sys.platform == 'win32': from relaax.server.common.win32_ctl_handler import set_console_ctrl_handler global g_ps g_ps = ps set_console_ctrl_handler(handler_event) while not cls.stopped_server: watch.check() try: events.get(timeout=1) except Empty: pass except Exception: break ps.save_checkpoint() speedm.stop_timer() except KeyboardInterrupt: # swallow KeyboardInterrupt pass
def run(cls, socket, address): try: if hasattr(options.relaax_rlx_server, 'profile_dir'): profiling.set_handlers([ profiling.FileHandler( os.path.join(options.relaax_rlx_server.profile_dir, 'rlx_%d.txt' % os.getpid())) ]) profiling.enable(True) cls.load_protocol() cls.load_algorithm() log.debug('Running worker on connection %s:%d' % address) options.protocol.adoptConnection(socket, address) except Exception as e: log.error("Error while running worker on connection %s : %s" % (address, str(e))) log.debug(traceback.format_exc())