Example #1
0
    def print_stats(self):
        if self._started:
            self._total += self._cnt
            stopped = rtime()
            cps = float(self._cnt) / float(stopped - self._started)
            print("{} calls/s ({} succeeded)".format(cps, self._total))

        self._started = rtime()
        self._cnt = 0
Example #2
0
    def trigger_gc(self, details=None):
        """
        Manually trigger a garbage collection in this native process.

        This procedure is registered under
        ``crossbar.node.<node_id>.worker.<worker_id>.trigger_gc``
        for native workers and under
        ``crossbar.node.<node_id>.controller.trigger_gc``
        for node controllers.

        The procedure will publish an event when the garabage collection has finished to
        ``crossbar.node.<node_id>.worker.<worker_id>.on_gc_finished``
        for native workers and
        ``crossbar.node.<node_id>.controller.on_gc_finished``
        for node controllers:

        .. code-block:: javascript

            {
                "requester": {
                    "session_id": 982734923,
                    "auth_id": "bob",
                    "auth_role": "admin"
                },
                "duration": 190
            }

        .. note:: The caller of this procedure will NOT receive the event.

        :returns: Time (wall clock) consumed for garbage collection in ms.
        :rtype: int
        """
        self.log.debug("{cls}.trigger_gc", cls=self.__class__.__name__)

        started = rtime()

        # now trigger GC .. this is blocking!
        gc.collect()

        duration = int(round(1000. * (rtime() - started)))

        on_gc_finished = u'{}.on_gc_finished'.format(self._uri_prefix)
        self.publish(
            on_gc_finished,
            {
                u'requester': {
                    u'session_id': details.caller,
                    # FIXME:
                    u'auth_id': None,
                    u'auth_role': None
                },
                u'duration': duration
            },
            options=PublishOptions(exclude=details.caller)
        )

        return duration
Example #3
0
    def print_stats(self):
        if self._started:
            self._total += self._cnt
            stopped = rtime()
            cps = float(self._cnt) / float(stopped - self._started)
            print ("{} calls/s ({} succeeded)".format(cps, self._total))

        self._started = rtime()
        self._cnt = 0
Example #4
0
    def trigger_gc(self, details=None):
        """
        Triggers a garbage collection.

        :returns: float -- Time consumed for GC in ms.
        """
        self.msg.debug("{cls}.trigger_gc", cls=self.__class__.__name__)

        started = rtime()
        gc.collect()
        return 1000. * (rtime() - started)
Example #5
0
    def trigger_gc(self, details=None):
        """
        Triggers a garbage collection.

        :returns: float -- Time consumed for GC in ms.
        """
        self.msg.debug("{cls}.trigger_gc", cls=self.__class__.__name__)

        started = rtime()
        gc.collect()
        return 1000. * (rtime() - started)
Example #6
0
    def trigger_gc(self, details=None):
        """
        Triggers a garbage collection.

        :returns: float -- Time consumed for GC in ms.
        """
        if self.debug:
            log.msg("{}.trigger_gc".format(self.__class__.__name__))

        started = rtime()
        gc.collect()
        return 1000. * (rtime() - started)
Example #7
0
   def trigger_gc(self, details = None):
      """
      Triggers a garbage collection.

      :returns: float -- Time consumed for GC in ms.
      """
      if self.debug:
         log.msg("{}.trigger_gc".format(self.__class__.__name__))

      started = rtime()
      gc.collect()
      return 1000. * (rtime() - started)
Example #8
0
    def connectionMade(self):
        print("session ready")
        self._send_queue = deque()
        self.send_queued_stuff()

        self._stop_calling = False
        self._done = False
        self._cnt_outstanding = 0
        self._started = None
        self._total = 0
        self._debug = False

        lc = LoopingCall(self.print_stats)
        lc.start(1)

        def stop():
            lc.stop()
            self._stop_calling = True
            self._done = True
            self._test_ended = rtime()
            self.stop()

        reactor.callLater(self.RUNTIME, stop)

        self._test_started = rtime()
        self.issue_calls()
Example #9
0
    def connectionMade(self):
        print ("session ready")
        self._send_queue = deque()
        self.send_queued_stuff()

        self._stop_calling = False
        self._done = False
        self._cnt_outstanding = 0
        self._started = None
        self._total = 0
        self._debug = False

        lc = LoopingCall(self.print_stats)
        lc.start(1)

        def stop():
            lc.stop()
            self._stop_calling = True
            self._done = True
            self._test_ended = rtime()
            self.stop()

        reactor.callLater(self.RUNTIME, stop)

        self._test_started = rtime()
        self.issue_calls()
Example #10
0
 def _connect(self):
    if len(self._connected) < self._target:
       if self._pending <= self._low_watermark:
          #print("low watermark reached ({} pending)".format(self._pending))
          self._connect_more()
       #else:
       #print len(self._connected)
       reactor.callLater(0.01, self._connect)
    else:
       self._do_print_stats = False
       self._ended = rtime()
       secs = self._ended - self._started
       conns_per_sec = float(len(self._connected)) / float(secs)
       print("all connected: {} in {} seconds ({} connections/sec)".format(len(self._connected), secs, conns_per_sec))
       reactor.stop()
Example #11
0
 def run(self):
    print("Starting ..")
    self._started = rtime()
    self._ended = None
    self._print_stats()
    self._connect()
Example #12
0
 def _post(self, session, result):
     duration = round(1000. * (rtime() - self._started), 1)
     self._started = None
     return CmdRunResult(result, duration)
Example #13
0
 def _pre(self, session):
     if not session:
         raise Exception('not connected')
     self._started = rtime()
Example #14
0
 def stop():
     lc.stop()
     self._stop_calling = True
     self._done = True
     self._test_ended = rtime()
     self.stop()
Example #15
0
 def stop():
     lc.stop()
     self._stop_calling = True
     self._done = True
     self._test_ended = rtime()
     self.stop()