Beispiel #1
0
    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 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
Beispiel #3
0
    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())
Beispiel #4
0
 def tearDown(self):
     profiling.set_handlers(self.handlers)
Beispiel #5
0
 def setUp(self):
     self.handlers = profiling.get_handlers()
     self.mh = MemoryHandler()
     profiling.set_handlers([self.mh])
     print(id(self))