From eb87474b480f77cd2849156136101f642202fed3 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Sun, 17 Jul 2022 13:36:18 -0400 Subject: [PATCH] expose tx_cache_size setting --- hub/db/db.py | 4 ++-- hub/herald/db.py | 4 ++-- hub/herald/env.py | 12 +++++++++--- hub/herald/service.py | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/hub/db/db.py b/hub/db/db.py index 6811dba..f14fe93 100644 --- a/hub/db/db.py +++ b/hub/db/db.py @@ -40,7 +40,7 @@ class SecondaryDB: cache_all_claim_txos: bool = False, cache_all_tx_hashes: bool = False, blocking_channel_ids: List[str] = None, filtering_channel_ids: List[str] = None, executor: ThreadPoolExecutor = None, - index_address_status=False, merkle_cache_size=32768): + index_address_status=False, merkle_cache_size=32768, tx_cache_size=32768): self.logger = logging.getLogger(__name__) self.coin = coin self._executor = executor @@ -90,7 +90,7 @@ class SecondaryDB: self.header_mc = MerkleCache(self.merkle, self.fs_block_hashes) # lru cache of tx_hash: (tx_bytes, tx_num, position, tx_height) - self.tx_cache = LRUCacheWithMetrics(2 ** 15, metric_name='tx', namespace=NAMESPACE) + self.tx_cache = LRUCacheWithMetrics(tx_cache_size, metric_name='tx', namespace=NAMESPACE) # lru cache of block heights to merkle trees of the block tx hashes self.merkle_cache = LRUCacheWithMetrics(merkle_cache_size, metric_name='merkle', namespace=NAMESPACE) diff --git a/hub/herald/db.py b/hub/herald/db.py index 23692c1..fa0153a 100644 --- a/hub/herald/db.py +++ b/hub/herald/db.py @@ -9,10 +9,10 @@ class HeraldDB(SecondaryDB): cache_all_claim_txos: bool = False, cache_all_tx_hashes: bool = False, blocking_channel_ids: List[str] = None, filtering_channel_ids: List[str] = None, executor: ThreadPoolExecutor = None, - index_address_status=False, merkle_cache_size=32768): + index_address_status=False, merkle_cache_size=32768, tx_cache_size=32768): super().__init__(coin, db_dir, secondary_name, max_open_files, reorg_limit, cache_all_claim_txos, cache_all_tx_hashes, blocking_channel_ids, filtering_channel_ids, executor, - index_address_status, merkle_cache_size) + index_address_status, merkle_cache_size, tx_cache_size) # self.headers = None # async def _read_headers(self): diff --git a/hub/herald/env.py b/hub/herald/env.py index e6b57fb..5a78f7f 100644 --- a/hub/herald/env.py +++ b/hub/herald/env.py @@ -12,7 +12,7 @@ class ServerEnv(Env): database_query_timeout=None, elastic_notifier_host=None, elastic_notifier_port=None, blocking_channel_ids=None, filtering_channel_ids=None, peer_hubs=None, peer_announce=None, index_address_status=None, address_history_cache_size=None, daemon_ca_path=None, - merkle_cache_size=None, resolved_url_cache_size=None): + merkle_cache_size=None, resolved_url_cache_size=None, tx_cache_size=None): super().__init__(db_dir, max_query_workers, chain, reorg_limit, prometheus_port, cache_all_tx_hashes, cache_all_claim_txos, blocking_channel_ids, filtering_channel_ids, index_address_status) self.daemon_url = daemon_url if daemon_url is not None else self.required('DAEMON_URL') @@ -57,6 +57,8 @@ class ServerEnv(Env): self.merkle_cache_size = merkle_cache_size if merkle_cache_size is not None else self.integer('MERKLE_CACHE_SIZE', 32768) self.resolved_url_cache_size = resolved_url_cache_size if resolved_url_cache_size is not None else self.integer( 'RESOLVED_URL_CACHE_SIZE', 32768) + self.tx_cache_size = tx_cache_size if tx_cache_size is not None else self.integer( + 'TX_CACHE_SIZE', 32768) @classmethod def contribute_to_arg_parser(cls, parser): @@ -117,7 +119,10 @@ class ServerEnv(Env): default=cls.integer('RESOLVED_URL_CACHE_SIZE', 32768), help="Size of the lru cache of resolved urls. " "Can be set in the env with 'RESOLVED_URL_CACHE_SIZE'") - + parser.add_argument('--tx_cache_size', type=int, + default=cls.integer('TX_CACHE_SIZE', 32768), + help="Size of the lru cache of transactions. " + "Can be set in the env with 'TX_CACHE_SIZE'") @classmethod def from_arg_parser(cls, args): return cls( @@ -134,5 +139,6 @@ class ServerEnv(Env): filtering_channel_ids=args.filtering_channel_ids, elastic_notifier_host=args.elastic_notifier_host, elastic_notifier_port=args.elastic_notifier_port, index_address_status=args.index_address_statuses, address_history_cache_size=args.address_history_cache_size, daemon_ca_path=args.daemon_ca_path, - merkle_cache_size=args.merkle_cache_size, resolved_url_cache_size=args.resolved_url_cache_size + merkle_cache_size=args.merkle_cache_size, resolved_url_cache_size=args.resolved_url_cache_size, + tx_cache_size=args.tx_cache_size ) diff --git a/hub/herald/service.py b/hub/herald/service.py index a792706..3a2a71c 100644 --- a/hub/herald/service.py +++ b/hub/herald/service.py @@ -42,7 +42,8 @@ class HubServerService(BlockchainReaderService): env.coin, env.db_dir, self.secondary_name, -1, env.reorg_limit, env.cache_all_claim_txos, env.cache_all_tx_hashes, blocking_channel_ids=env.blocking_channel_ids, filtering_channel_ids=env.filtering_channel_ids, executor=self._executor, - index_address_status=env.index_address_status, merkle_cache_size=env.merkle_cache_size + index_address_status=env.index_address_status, merkle_cache_size=env.merkle_cache_size, + tx_cache_size=env.tx_cache_size ) def clear_caches(self):