Browse Source

Don't maintain a sub_count in controller

Just do a tally occasionally.
It's too tricky to keep it accurate as it double-counts resubscribing to
the same address, for example
master
Neil Booth 8 years ago
parent
commit
766da5ed79
  1. 2
      lib/hash.py
  2. 2
      lib/script.py
  3. 2
      lib/tx.py
  4. 2
      lib/util.py
  5. 15
      server/controller.py

2
lib/hash.py

@ -1,4 +1,4 @@
# Copyright (c) 2016, Neil Booth
# Copyright (c) 2016-2017, Neil Booth
#
# All rights reserved.
#

2
lib/script.py

@ -1,4 +1,4 @@
# Copyright (c) 2016, Neil Booth
# Copyright (c) 2016-2017, Neil Booth
#
# All rights reserved.
#

2
lib/tx.py

@ -1,4 +1,4 @@
# Copyright (c) 2016, Neil Booth
# Copyright (c) 2016-2017, Neil Booth
#
# All rights reserved.
#

2
lib/util.py

@ -1,4 +1,4 @@
# Copyright (c) 2016, Neil Booth
# Copyright (c) 2016-2017, Neil Booth
#
# All rights reserved.
#

15
server/controller.py

@ -73,7 +73,8 @@ class Controller(util.LoggedClass):
self.max_sessions = env.max_sessions
self.low_watermark = self.max_sessions * 19 // 20
self.max_subs = env.max_subs
self.subscription_count = 0
# Cache some idea of room to avoid recounting on each subscription
self.subs_room = 0
self.next_stale_check = 0
self.history_cache = pylru.lrucache(256)
self.header_cache = pylru.lrucache(8)
@ -374,7 +375,6 @@ class Controller(util.LoggedClass):
gid = self.sessions.pop(session)
assert gid in self.groups
self.groups[gid].remove(session)
self.subscription_count -= session.sub_count()
def close_session(self, session):
'''Close the session's transport and cancel its future.'''
@ -436,10 +436,13 @@ class Controller(util.LoggedClass):
'peers': len(self.irc.peers),
'requests': sum(s.requests_remaining() for s in self.sessions),
'sessions': self.session_count(),
'subs': self.subscription_count,
'subs': self.sub_count(),
'txs_sent': self.txs_sent,
}
def sub_count(self):
return sum(s.sub_count() for s in self.sessions)
@staticmethod
def text_lines(method, data):
if method == 'sessions':
@ -642,10 +645,12 @@ class Controller(util.LoggedClass):
raise RPCError('daemon error: {}'.format(e))
async def new_subscription(self, address):
if self.subscription_count >= self.max_subs:
if self.subs_room <= 0:
self.subs_room = self.max_subs - self.sub_count()
if self.subs_room <= 0:
raise RPCError('server subscription limit {:,d} reached'
.format(self.max_subs))
self.subscription_count += 1
self.subs_room -= 1
hashX = self.address_to_hashX(address)
status = await self.address_status(hashX)
return hashX, status

Loading…
Cancel
Save