Commit 793dfeba by ‘chizw’

[+]内存优化

1 parent e2ff9348
......@@ -9,7 +9,9 @@ from log.logger import log
from config.config import ConfigInfo
from concurrent.futures import ThreadPoolExecutor
from kafka.structs import TopicPartition
from tqdm import tqdm
from mysql_service import funasr_db
import numpy as np
# 配置 Kafka 消费者
consumer_new = KafkaConsumer(
......@@ -78,7 +80,13 @@ def consume_kafka():
log.info(f"启动consume_kafka Thread name:{threading.current_thread().name}")
# 消费消息并进行逻辑处理
try:
# 先创建进程池,只复制当前资源
multiprocessing.set_start_method('spawn')
process_pool = multiprocessing.Pool(processes=2, initializer=consumer_process_init)
# m = multiprocessing.Manager()
# q = m.JoinableQueue()
# # 加载大内存变量
# larg_mem = np.random.normal(1.0, 0.1, 10000000)
for message in consumer_new:
if message is None:
continue
......@@ -87,6 +95,7 @@ def consume_kafka():
# funasr_service.handle_process(str(message.value.decode('utf-8')))
arg = str(message.value.decode('utf-8'))
log.info(f"arg:{arg},process_pool1:{process_pool}")
# print(list((tqdm(p.imap(f, range(10)), total=10, desc='监视进度'))))
process_pool.apply_async(func=funasr_service.handle_process, args=(arg,),
callback=consumer_process_callback,
error_callback=consumer_process_error_callback)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!