Browse Source

Add REQUEST_TIMEOUT environment variable

patch-2
Neil Booth 6 years ago
parent
commit
1129e50252
  1. 15
      docs/environment.rst
  2. 1
      electrumx/server/env.py
  3. 2
      electrumx/server/session.py
  4. 4
      tests/server/test_env.py

15
docs/environment.rst

@ -294,11 +294,20 @@ raise them.
The default value :const:`5,000` bytes, meaning the bandwidth cost assigned to a response The default value :const:`5,000` bytes, meaning the bandwidth cost assigned to a response
of 100KB is 20. If your bandwidth is cheap you should probably raise this. of 100KB is 20. If your bandwidth is cheap you should probably raise this.
.. envvar:: REQUEST_TIMEOUT
An integer number of seconds defaulting to :const:`15`. If a request takes longer than
this to respond to, either because of request limiting or because the request is
expensive, the server rejects it and returns a timeout error to the client indicating
that the server is busy.
This can help prevent large backlogs of unprocessed requests building up under heavy load.
.. envvar:: SESSION_TIMEOUT .. envvar:: SESSION_TIMEOUT
An integer number of seconds defaulting to 600. Sessions that have not sent a request An integer number of seconds defaulting to :const:`600`. Sessions that have not sent a
for longer than this are disconnected. Properly functioning clients should send a request for longer than this are disconnected. Properly functioning clients should send
:func:`server.ping` request once roughly 450 seconds have passed since the previous a :func:`server.ping` request once roughly 450 seconds have passed since the previous
request, in order to avoid disconnection. request, in order to avoid disconnection.

1
electrumx/server/env.py

@ -73,6 +73,7 @@ class Env(EnvBase):
self.bw_unit_cost = self.integer('BANDWIDTH_UNIT_COST', 5000) self.bw_unit_cost = self.integer('BANDWIDTH_UNIT_COST', 5000)
self.initial_concurrent = self.integer('INITIAL_CONCURRENT', 10) self.initial_concurrent = self.integer('INITIAL_CONCURRENT', 10)
self.request_sleep = self.integer('REQUEST_SLEEP', 2500) self.request_sleep = self.integer('REQUEST_SLEEP', 2500)
self.request_timeout = self.integer('REQUEST_TIMEOUT', 15)
self.session_timeout = self.integer('SESSION_TIMEOUT', 600) self.session_timeout = self.integer('SESSION_TIMEOUT', 600)
self.drop_client = self.custom("DROP_CLIENT", None, re.compile) self.drop_client = self.custom("DROP_CLIENT", None, re.compile)
self.blacklist_url = self.default('BLACKLIST_URL', self.coin.BLACKLIST_URL) self.blacklist_url = self.default('BLACKLIST_URL', self.coin.BLACKLIST_URL)

2
electrumx/server/session.py

@ -487,6 +487,7 @@ class SessionManager(object):
session_class.bw_cost_per_byte = 1.0 / self.env.bw_unit_cost session_class.bw_cost_per_byte = 1.0 / self.env.bw_unit_cost
session_class.cost_sleep = self.env.request_sleep / 1000 session_class.cost_sleep = self.env.request_sleep / 1000
session_class.initial_concurrent = self.env.initial_concurrent session_class.initial_concurrent = self.env.initial_concurrent
session_class.processing_timeout = self.env.request_timeout
self.logger.info(f'max session count: {self.env.max_sessions:,d}') self.logger.info(f'max session count: {self.env.max_sessions:,d}')
self.logger.info(f'session timeout: {self.env.session_timeout:,d} seconds') self.logger.info(f'session timeout: {self.env.session_timeout:,d} seconds')
@ -494,6 +495,7 @@ class SessionManager(object):
self.logger.info(f'session cost soft limit {self.env.cost_soft_limit:,d}') self.logger.info(f'session cost soft limit {self.env.cost_soft_limit:,d}')
self.logger.info(f'bandwidth unit cost {self.env.bw_unit_cost:,d}') self.logger.info(f'bandwidth unit cost {self.env.bw_unit_cost:,d}')
self.logger.info(f'request sleep {self.env.request_sleep:,d}ms') self.logger.info(f'request sleep {self.env.request_sleep:,d}ms')
self.logger.info(f'request timeout {self.env.request_timeout:,d}s')
self.logger.info(f'initial concurrent {self.env.initial_concurrent:,d}') self.logger.info(f'initial concurrent {self.env.initial_concurrent:,d}')
self.logger.info(f'max response size {self.env.max_send:,d} bytes') self.logger.info(f'max response size {self.env.max_send:,d} bytes')

4
tests/server/test_env.py

@ -236,6 +236,10 @@ def test_MAX_SESSIONS():
# Cannot test default as it may be lowered by the open file limit cap # Cannot test default as it may be lowered by the open file limit cap
def test_REQUEST_TIMEOUT():
assert_integer('REQUEST_TIMEOUT', 'request_timeout', 15)
def test_SESSION_TIMEOUT(): def test_SESSION_TIMEOUT():
assert_integer('SESSION_TIMEOUT', 'session_timeout', 600) assert_integer('SESSION_TIMEOUT', 'session_timeout', 600)

Loading…
Cancel
Save