Example #1
0
    def onJoin(self, details):
        self._db = Database(dbpath='../results')
        self._schema = Schema.attach(self._db)

        self._pinfo = ProcessInfo()
        self._logname = self.config.extra['logname']
        self._period = self.config.extra.get('period', 10.)
        self._running = True

        batch_id = uuid.uuid4()

        self._last_stats = None
        self._stats_loop = LoopingCall(self._stats, batch_id)
        self._stats_loop.start(self._period)

        dl = []
        for i in range(8):
            d = self._loop(batch_id, i)
            dl.append(d)
        d = gatherResults(dl)

        try:
            yield d
        except TransportLost:
            pass
Example #2
0
    def onConnect(self, do_join=True):
        """
        """
        if not hasattr(self, 'cbdir'):
            self.cbdir = self.config.extra.cbdir

        if not hasattr(self, '_uri_prefix'):
            self._uri_prefix = 'crossbar.node.{}'.format(
                self.config.extra.node)

        self._started = datetime.utcnow()

        # see: BaseSession
        self.include_traceback = False

        self._manhole_service = None

        if _HAS_PSUTIL:
            self._pinfo = ProcessInfo()
            self._pinfo_monitor = None
            self._pinfo_monitor_seq = 0
        else:
            self._pinfo = None
            self._pinfo_monitor = None
            self._pinfo_monitor_seq = None
            self.log.info("Process utilities not available")

        self._connections = {}

        if do_join:
            self.join(self.config.realm)
Example #3
0
    def onJoin(self, details):

        self._prefix = self.config.extra['prefix']
        self._logname = self.config.extra['logname']

        self._pinfo = ProcessInfo()

        def echo(arg):
            return arg

        yield self.register(echo,
                            '{}.echo'.format(self._prefix),
                            options=RegisterOptions(invoke='roundrobin'))

        self.log.info('{} ready!'.format(self._logname))

        last = None
        while True:
            stats = self._pinfo.get_stats()
            if last:
                secs = (stats['time'] - last['time']) / 10**9
                ctx = round((stats['voluntary'] - last['voluntary']) / secs, 0)
                self.log.info('{logname}: {cpu} cpu, {mem} mem, {ctx} ctx',
                              logname=self._logname,
                              cpu=round(stats['cpu_percent'], 1),
                              mem=round(stats['mem_percent'], 1),
                              ctx=ctx)
            last = stats
            yield sleep(5)
Example #4
0
    def on_worker_connected(self, proto):
        """
        Called immediately after the worker process has been forked.

        IMPORTANT: this slightly differs between native workers and guest workers!
        """
        assert (self.status == u'starting')
        assert (self.connected is None)
        assert (self.proto is None)
        assert (self.pid is None)
        assert (self.pinfo is None)
        self.status = u'connected'
        self.connected = datetime.utcnow()
        self.proto = proto
        self.pid = proto.transport.pid
        self.pinfo = ProcessInfo(self.pid)
Example #5
0
    def onJoin(self, details):

        self._prefix = self.config.extra['prefix']
        self._logname = self.config.extra['logname']
        self._count = 0

        self._pinfo = ProcessInfo()

        def echo(arg):
            self._count += 1
            return arg

        yield self.register(echo,
                            '{}.echo'.format(self._prefix),
                            options=RegisterOptions(invoke='roundrobin'))

        self.log.info('{} ready!'.format(self._logname))

        last = None
        while True:
            stats = self._pinfo.get_stats()
            if last:
                secs = (stats['time'] - last['time']) / 10**9
                calls_per_sec = int(round(self._count / secs, 0))
                ctx = round((stats['voluntary'] - last['voluntary']) / secs, 0)

                self.log.info(
                    '{logprefix}: {user} user, {system} system, {mem_percent} mem_percent, {ctx} ctx',
                    logprefix=hl('LOAD {}'.format(self._logname),
                                 color='cyan',
                                 bold=True),
                    user=stats['user'],
                    system=stats['system'],
                    mem_percent=round(stats['mem_percent'], 1),
                    ctx=ctx)
                self.log.info(
                    '{logprefix}: {calls} calls, {calls_per_sec} calls/second',
                    logprefix=hl('WAMP {}'.format(self._logname),
                                 color='cyan',
                                 bold=True),
                    calls=self._count,
                    calls_per_sec=hl(calls_per_sec, bold=True))

                self._count = 0

            last = stats
            yield sleep(10)
Example #6
0
    def onJoin(self, details):
        self._db = Database(dbpath='../results')
        self._schema = Schema.attach(self._db)

        self._pinfo = ProcessInfo()
        self._logname = self.config.extra['logname']
        self._period = self.config.extra.get('period', 5.)
        self._running = True

        dl = []
        for i in range(8):
            d = self._loop(i)
            dl.append(d)

        d = gatherResults(dl)

        try:
            yield d
        except TransportLost:
            pass
Example #7
0
    def on_worker_started(self, proto=None):
        """
        Called after the worker process is connected to the node
        router and registered all its management APIs there.

        The worker is now ready for use!
        """
        assert (self.status in [u'starting', u'connected'])
        assert (self.started is None)
        assert (self.proto is not None or proto is not None)

        if not self.pid:
            self.pid = proto.transport.pid
        if not self.pinfo:
            self.pinfo = ProcessInfo(self.pid)

        assert (self.pid is not None)
        assert (self.pinfo is not None)

        self.status = u'started'
        self.proto = self.proto or proto
        self.started = datetime.utcnow()
Example #8
0
    def onConnect(self, do_join=True):
        """
        """
        if not hasattr(self, 'debug'):
            self.debug = self.config.extra.debug

        if not hasattr(self, 'cbdir'):
            self.cbdir = self.config.extra.cbdir

        if not hasattr(self, '_uri_prefix'):
            self._uri_prefix = 'crossbar.node.{}'.format(
                self.config.extra.node)

        if self.debug:
            log.msg("Session connected to management router")

        self._started = datetime.utcnow()

        # see: BaseSession
        self.include_traceback = False
        self.debug_app = False

        self._manhole_service = None

        if _HAS_PSUTIL:
            self._pinfo = ProcessInfo()
            self._pinfo_monitor = None
            self._pinfo_monitor_seq = 0
        else:
            self._pinfo = None
            self._pinfo_monitor = None
            self._pinfo_monitor_seq = None
            log.msg("Warning: process utilities not available")

        if do_join:
            self.join(self.config.realm)
Example #9
0
    def onJoin(self, details):
        self._pid = os.getpid()

        # benchmark parametrization:
        self._period = self.config.extra.get('period', 10)
        self._loops = self.config.extra.get('loops', 1)
        self._rate = self.config.extra.get('rate', 1)
        self._stride = self.config.extra.get('stride', 1)
        self._size = self.config.extra.get('size', 256)
        self._logname = self.config.extra.get('logname', None)
        self._url = self.config.extra.get('url', None)
        self._silent = self.config.extra.get('silent', False)

        self._batch_id = uuid.uuid4()
        self._running = True
        self._pinfo = ProcessInfo()

        # run-time session statistics for EVENTs
        self._received_cnt = 0
        self._received_bytes = 0
        self._received_ff_cnt = 0
        self._published_cnt = 0
        self._published_bytes = 0

        # run-time session statistics for CALLs
        self._received_calls_cnt = 0
        self._received_calls_bytes = 0
        self._received_calls_ff_cnt = 0
        self._calls_cnt = 0
        self._calls_bytes = 0

        self.log.info('{logname} connected [batch="{batch_id}"]: {details}',
                      logname=self._logname,
                      batch_id=hl(self._batch_id),
                      details=details)

        self._last_stats = None
        self._stats_loop = None

        if self._silent:
            self._stats(self._batch_id, self.log.info)

        stats_period = 10.
        if stats_period:
            self._stats_loop = LoopingCall(self._stats, self._batch_id,
                                           self.log.info)
            self._stats_loop.start(stats_period)

        yield self.subscribe(self.on_event1,
                             HATestClientSession.TEST_TOPIC,
                             options=SubscribeOptions(match='exact',
                                                      details=True))

        for i in range(self._loops):
            self._sender_loop('{}.{}'.format(self._logname, i))

        self.log.info(
            '{logname} ready [period={period}, loops={loops}, rate={rate}, stride={stride}, size={size}]',
            logname=self._logname,
            period=self._period,
            loops=self._loops,
            rate=self._rate,
            stride=self._stride,
            size=self._size)