mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-18 15:01:29 +08:00
Pref: Release rpc connection on idle so OCR can be load balanced
This commit is contained in:
@@ -91,7 +91,15 @@ def release_resources(next_task=''):
|
|||||||
# Usually to have 2 models loaded and each model takes about 20MB
|
# Usually to have 2 models loaded and each model takes about 20MB
|
||||||
# This will release 20-40MB
|
# This will release 20-40MB
|
||||||
from module.webui.setting import State
|
from module.webui.setting import State
|
||||||
if not State.deploy_config.UseOcrServer:
|
if State.deploy_config.UseOcrServer:
|
||||||
|
if not next_task:
|
||||||
|
# Disconnect OCR server on idle
|
||||||
|
from module.ocr.ocr import OCR_MODEL
|
||||||
|
try:
|
||||||
|
OCR_MODEL.close()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
# Release only when using per-instance OCR
|
# Release only when using per-instance OCR
|
||||||
from module.ocr.ocr import OCR_MODEL
|
from module.ocr.ocr import OCR_MODEL
|
||||||
if 'Opsi' in next_task or 'commission' in next_task:
|
if 'Opsi' in next_task or 'commission' in next_task:
|
||||||
|
|||||||
@@ -15,16 +15,25 @@ class ModelProxy:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def init(cls, address="127.0.0.1:22268"):
|
def init(cls, address="127.0.0.1:22268"):
|
||||||
import zerorpc
|
import zerorpc
|
||||||
|
|
||||||
|
logger.info(f"Connecting to OCR server {address}")
|
||||||
cls.client = zerorpc.Client(timeout=5)
|
cls.client = zerorpc.Client(timeout=5)
|
||||||
cls.client.connect(f"tcp://{address}")
|
cls.client.connect(f"tcp://{address}")
|
||||||
try:
|
try:
|
||||||
logger.info(f"Connecting to OCR server {address}")
|
|
||||||
cls.client.hello()
|
cls.client.hello()
|
||||||
logger.info("Successfully connected to OCR server")
|
logger.info("Successfully connected to OCR server")
|
||||||
except:
|
except:
|
||||||
cls.online = False
|
cls.online = False
|
||||||
logger.warning("Ocr server not running")
|
logger.warning("Ocr server not running")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def close(cls):
|
||||||
|
if cls.client is not None:
|
||||||
|
logger.info('Disconnect to OCR server')
|
||||||
|
cls.client.close()
|
||||||
|
logger.info('Successfully disconnected to OCR server')
|
||||||
|
cls.client = None
|
||||||
|
|
||||||
def __init__(self, lang) -> None:
|
def __init__(self, lang) -> None:
|
||||||
self.lang = lang
|
self.lang = lang
|
||||||
|
|
||||||
@@ -169,6 +178,9 @@ class ModelProxyFactory:
|
|||||||
else:
|
else:
|
||||||
return super().__getattribute__(__name)
|
return super().__getattribute__(__name)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
ModelProxy.close()
|
||||||
|
|
||||||
|
|
||||||
def start_ocr_server(port=22268):
|
def start_ocr_server(port=22268):
|
||||||
import zerorpc
|
import zerorpc
|
||||||
|
|||||||
Reference in New Issue
Block a user