Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
funasr_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 793dfeba
authored
Dec 18, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]内存优化
1 parent
e2ff9348
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
0 deletions
kafka_service/funasr_consumer.py
kafka_service/funasr_consumer.py
View file @
793dfeb
...
@@ -9,7 +9,9 @@ from log.logger import log
...
@@ -9,7 +9,9 @@ from log.logger import log
from
config.config
import
ConfigInfo
from
config.config
import
ConfigInfo
from
concurrent.futures
import
ThreadPoolExecutor
from
concurrent.futures
import
ThreadPoolExecutor
from
kafka.structs
import
TopicPartition
from
kafka.structs
import
TopicPartition
from
tqdm
import
tqdm
from
mysql_service
import
funasr_db
from
mysql_service
import
funasr_db
import
numpy
as
np
# 配置 Kafka 消费者
# 配置 Kafka 消费者
consumer_new
=
KafkaConsumer
(
consumer_new
=
KafkaConsumer
(
...
@@ -78,7 +80,13 @@ def consume_kafka():
...
@@ -78,7 +80,13 @@ def consume_kafka():
log
.
info
(
f
"启动consume_kafka Thread name:{threading.current_thread().name}"
)
log
.
info
(
f
"启动consume_kafka Thread name:{threading.current_thread().name}"
)
# 消费消息并进行逻辑处理
# 消费消息并进行逻辑处理
try
:
try
:
# 先创建进程池,只复制当前资源
multiprocessing
.
set_start_method
(
'spawn'
)
process_pool
=
multiprocessing
.
Pool
(
processes
=
2
,
initializer
=
consumer_process_init
)
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
:
for
message
in
consumer_new
:
if
message
is
None
:
if
message
is
None
:
continue
continue
...
@@ -87,6 +95,7 @@ def consume_kafka():
...
@@ -87,6 +95,7 @@ def consume_kafka():
# funasr_service.handle_process(str(message.value.decode('utf-8')))
# funasr_service.handle_process(str(message.value.decode('utf-8')))
arg
=
str
(
message
.
value
.
decode
(
'utf-8'
))
arg
=
str
(
message
.
value
.
decode
(
'utf-8'
))
log
.
info
(
f
"arg:{arg},process_pool1:{process_pool}"
)
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
,),
process_pool
.
apply_async
(
func
=
funasr_service
.
handle_process
,
args
=
(
arg
,),
callback
=
consumer_process_callback
,
callback
=
consumer_process_callback
,
error_callback
=
consumer_process_error_callback
)
error_callback
=
consumer_process_error_callback
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment