connector
This commit is contained in:
parent
1f7334718c
commit
0c3ca9588d
@ -13,7 +13,9 @@ import pickle
|
|||||||
|
|
||||||
class BlockLoader:
|
class BlockLoader:
|
||||||
def __init__(self, parent, workers=4):
|
def __init__(self, parent, workers=4):
|
||||||
|
self.worker_limit = workers
|
||||||
self.worker = dict()
|
self.worker = dict()
|
||||||
|
self.worker_tasks = list()
|
||||||
self.worker_busy = dict()
|
self.worker_busy = dict()
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.loading_task = None
|
self.loading_task = None
|
||||||
@ -24,7 +26,7 @@ class BlockLoader:
|
|||||||
self.rpc_batch_limit = parent.rpc_batch_limit
|
self.rpc_batch_limit = parent.rpc_batch_limit
|
||||||
self.loop.set_default_executor(ThreadPoolExecutor(workers * 2))
|
self.loop.set_default_executor(ThreadPoolExecutor(workers * 2))
|
||||||
self.watchdog_task = self.loop.create_task(self.watchdog())
|
self.watchdog_task = self.loop.create_task(self.watchdog())
|
||||||
[self.loop.create_task(self.start_worker(i)) for i in range(workers)]
|
|
||||||
|
|
||||||
async def watchdog(self):
|
async def watchdog(self):
|
||||||
while True:
|
while True:
|
||||||
@ -46,6 +48,7 @@ class BlockLoader:
|
|||||||
|
|
||||||
|
|
||||||
async def loading(self):
|
async def loading(self):
|
||||||
|
self.worker_tasks = [self.loop.create_task(self.start_worker(i)) for i in range(self.worker_limit)]
|
||||||
target_height = self.parent.node_last_block - self.parent.self.deep_sync_limit
|
target_height = self.parent.node_last_block - self.parent.self.deep_sync_limit
|
||||||
height = self.parent.last_block_height + 1
|
height = self.parent.last_block_height + 1
|
||||||
while height < target_height:
|
while height < target_height:
|
||||||
@ -57,6 +60,7 @@ class BlockLoader:
|
|||||||
for i in self.worker_busy:
|
for i in self.worker_busy:
|
||||||
if not self.worker_busy[i]:
|
if not self.worker_busy[i]:
|
||||||
self.worker_busy[i] = True
|
self.worker_busy[i] = True
|
||||||
|
self.log.info(">>>")
|
||||||
self.pipe_sent_msg(self.worker[i].writer, b'get', int_to_bytes(height))
|
self.pipe_sent_msg(self.worker[i].writer, b'get', int_to_bytes(height))
|
||||||
height += self.rpc_batch_limit
|
height += self.rpc_batch_limit
|
||||||
new_requests += 1
|
new_requests += 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user