From 1dcb31de9bdbcf25241b56425ce98c1dca6dba9e Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 25 Apr 2019 22:50:06 +0100 Subject: [PATCH] session:py: _recalc_concurrency tweaks - aiorpcX's recalc_concurrency() no longer throws - only for sessions with slow-moving cost; those increasing fast are handled in aiorpcx - as not urgent reduce to running loop every 5 minutes --- electrumx/server/session.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/electrumx/server/session.py b/electrumx/server/session.py index 01c19c6..18b4f90 100644 --- a/electrumx/server/session.py +++ b/electrumx/server/session.py @@ -23,8 +23,7 @@ from ipaddress import ip_address, IPv4Address, IPv6Address import attr from aiorpcx import ( RPCSession, JSONRPCAutoDetect, JSONRPCConnection, - TaskGroup, handler_invocation, RPCError, Request, sleep, Event, - ExcessiveSessionCostError, ReplyAndDisconnect + TaskGroup, handler_invocation, RPCError, Request, sleep, Event, ReplyAndDisconnect ) import pylru @@ -251,7 +250,7 @@ class SessionManager(object): async def _recalc_concurrency(self): '''Periodically recalculate session concurrency.''' session_class = self.env.coin.SESSIONCLS - period = 100 + period = 300 while True: await sleep(period) hard_limit = session_class.cost_hard_limit @@ -267,16 +266,12 @@ class SessionManager(object): for group in dead_groups: self.session_groups.pop(group.name) - sessions_to_close = [] + # Recalc concurrency for sessions where cost is changing gradually, and update + # cost_decay_per_sec. for session in self.sessions: # Subs have an on-going cost so decay more slowly with more subs session.cost_decay_per_sec = hard_limit / (10000 + 5 * session.sub_count()) - try: - session.recalc_concurrency() - except ExcessiveSessionCostError: - sessions_to_close.append(session) - await self._disconnect_sessions(sessions_to_close, 'closing expensive') - del sessions_to_close + session.recalc_concurrency() def _get_info(self): '''A summary of server state.'''