Пример #1
0
  def on_thread_finished(self, _):
    # Update stats, nothing else is needed

    with STATS:
      STATS.inc(self.stats_name, 'Total threads finished')

    STATS.remove(self.stats_name, 'Threads', hruntime.tid)
Пример #2
0
  def commit(self):
    try:
      with STATS:
        STATS.inc(self.stats_name, 'Commits')

      self.log_transaction('pre-commit')
      transaction.commit()
      self.doom()
      self.log_transaction('post-commit')

    except ZODB.POSException.ConflictError, e:
      self.log_transaction('post-commit-fail')

      with STATS:
        STATS.inc(self.stats_name, 'Failed commits')

      print >> sys.stderr, 'Conflict Error:'
      print >> sys.stderr, '  class_name: ' + str(e.class_name)
      print >> sys.stderr, '  msg: ' + str(e.message)
      print >> sys.stderr, '  data: ' + str(e.args)
      print >> sys.stderr, '  info: ' + str(e.serials)

      #print traceback.format_exc()
      #print e

      return False
Пример #3
0
  def rollback(self):
    with STATS:
      STATS.inc(self.stats_name, 'Rollbacks')

    self.log_transaction('pre-abort')
    transaction.abort()
    self.doom()
    self.log_transaction('post-abort')
Пример #4
0
  def on_thread_start(self, _):
    # Setup hruntime info, and set stats record

    hruntime.service_engine = self.server.engine
    hruntime.service_server = self.server
    hruntime.service_thread = threading.current_thread()
    hruntime.tid = hruntime.service_thread.name

    STATS.set(self.stats_name, 'Threads', hruntime.tid, OrderedDict([
      ('Start time', time.time()),
      ('Uptime', lambda s: time.time() - s['Start time']),
      ('Time per request', lambda s: (float(s['Total time']) / float(s['Total requests'])) if s['Total requests'] > 0 else 0.0)
    ]))

    with STATS:
      STATS.inc(self.stats_name, 'Total threads started')
Пример #5
0
  def on_request_connected(self, _):
    hruntime.clean()
    hruntime.db.start_transaction()

    hruntime.dont_commit = True

    with STATS:
      STATS.inc(self.stats_name, 'Total requests')

    STATS.set(self.stats_name, 'Requests', hruntime.tid, OrderedDict([
      ('Bytes read',     0),
      ('Bytes written',  0),
      ('Client',         hlib.server.ips_to_str(hruntime.request.ips)),
      ('Start time',     hruntime.time),
      ('Requested line', None),
      ('User',           None)
    ]))
Пример #6
0
  def test_sanity(self):
    with STATS:
      STATS.set('key1', {
        'foo': 1,
        'bar': 2,
        'baz': {
          'key1_foo': 7
        }
      })

      EQ(STATS.get('key1', 'foo'), 1)
      EQ(STATS.get('key1', 'bar'), 2)
      EQ(STATS.get('key1', 'baz', 'key1_foo'), 7)

      STATS.inc('key1', 'foo')
      STATS.add('key1', 'bar', 2)
      STATS.inc('key1', 'baz', 'key1_foo')

      EQ(STATS.get('key1', 'foo'), 2)
      EQ(STATS.get('key1', 'bar'), 4)
      EQ(STATS.get('key1', 'baz', 'key1_foo'), 8)
Пример #7
0
 def stats_inc(self, key):
   with STATS:
     STATS.inc(self.stats_name, key)
Пример #8
0
 def db_stats_incer(*args):
   with STATS:
     STATS.inc(self.stats_name, *args)
Пример #9
0
  def on_request_connected(self, _):
    # Update stats, nothing else is needed

    STATS.inc(self.stats_name, 'Threads', hruntime.tid, 'Total requests')