Commit 53a42b26 by ‘chizw’

[+]oom优化

1 parent 24d7884e
......@@ -20,9 +20,9 @@ model = AutoModel(
device="cpu",
batch_size_s=100,
batch_size_threshold_s=60 * 60
# model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
# vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
# punc_model="iic/punc_ct-transformer_cn-en-common-vocab471067-large",
# model="iic/speech_paraformer-large-vad-punc_asr_nat-zh-cn-16k-common-vocab8404-pytorch",
# vad_model="iic/speech_fsmn_vad_zh-cn-16k-common-pytorch",
# punc_model="iic/punc_ct-transformer_cn-en-common-vocab471067-large",
)
......@@ -101,7 +101,7 @@ def deal_worker(task_id: str):
or exception_msg == "local variable 'raw_text' referenced before assignment":
funasr_db.update_ali_asr_model_res_skip(task_id)
return
funasr_db.update_process_task(task_id,str(multiprocessing.current_process().name))
funasr_db.update_process_task(task_id, str(multiprocessing.current_process().name))
url = sql_res[0]["file_url"]
if url == "" or len(url) < 1 or not url.startswith("http"):
funasr_db.update_ali_asr_model_res_skip(task_id)
......@@ -159,3 +159,15 @@ def merge_spk_transform_output(sentence_info):
output.append(model_output(spk, offset, duration, content).to_dict())
json_output = json.dumps(output, ensure_ascii=False)
return json_output
def task_compensate_send():
try:
log.info("task_compensate_send start")
res = funasr_db.select_time_out_task()
if res is not None and len(res) > 0:
for item in res:
funasr_producer.send_task_id(item["task_id"])
log.info("task_compensate_send end")
except Exception as e:
log.error("task_compensate_send error", e)
......@@ -117,13 +117,13 @@ def consumer_process_init():
def consumer_process_callback(res):
log.info(f"consumer_process_callback:{multiprocessing.current_process().name}, res:{res}")
count = funasr_db.select_process_all_end()
if count is not None and int(count) == 0:
res = funasr_db.select_ali_asr_model_wait()
if res is not None and len(res) > 0:
data = {"task_id": res[0]["task_id"]}
message = json.dumps(data).encode('utf-8')
funasr_service.handle_process(str(message))
# count = funasr_db.select_process_all_end()
# if count is not None and int(count) == 0:
# res = funasr_db.select_ali_asr_model_wait()
# if res is not None and len(res) > 0:
# data = {"task_id": res[0]["task_id"]}
# message = json.dumps(data).encode('utf-8')
# funasr_service.handle_process(str(message))
def consumer_process_error_callback(err):
......
......@@ -79,9 +79,19 @@ def update_process_task(task_id: str, process_name: str):
)
return pool.update_one(update_sql, (process_name, task_id))
def select_process_all_end():
sql = (
"select count(aamr.id) from ali_asr_model_res aamr where aamr.del_flag = 0 "
"and aamr.execute_process_name is not null and aamr.task_status = %s;"
)
return pool.select_all(sql, (0))
def select_time_out_task():
sql = (
"select id,task_id,file_url,task_status from ali_asr_model_res aamr where aamr.del_flag = 0 "
"and aamr.output_data is null and aamr.execute_process_name is not null and exception_limit < 3"
"and aamr.updated_time < TIMESTAMPADD(MINUTE, -%s, NOW());"
)
return pool.select_all(sql, (30))
import datetime
import time
import funasr_service
from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.mongodb import MongoDBJobStore
from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from log.logger import log
jobstores = {
'default': MemoryJobStore()
}
executors = {
'default': ThreadPoolExecutor(2),
# 'processpool': ProcessPoolExecutor(3)
}
job_defaults = {
'coalesce': True,
'max_instances': 3
}
def job_func():
print(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3])
def scheduler_start():
log.info("scheduler_starting...")
scheduler = BackgroundScheduler(executors=executors, job_defaults=job_defaults)
scheduler.add_job(funasr_service.task_compensate_send, 'interval', minutes=30)
scheduler.start()
log.info("scheduler_start success")
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!