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 cc524ed5
authored
Dec 19, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]进程优化
1 parent
a3b54806
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
9 deletions
funasr_service.py
kafka_service/funasr_consumer.py
main.py
funasr_service.py
View file @
cc524ed
...
@@ -67,7 +67,7 @@ else:
...
@@ -67,7 +67,7 @@ else:
model_revision
=
'v2.0.4'
,
model_revision
=
'v2.0.4'
,
vad_model_revision
=
'v2.0.4'
,
vad_model_revision
=
'v2.0.4'
,
punc_model_revision
=
'v2.0.4'
,
punc_model_revision
=
'v2.0.4'
,
ncpu
=
8
,
ncpu
=
4
,
ngpu
=
0
,
ngpu
=
0
,
device
=
"cpu"
,
device
=
"cpu"
,
batch_size
=
1
,
batch_size
=
1
,
...
...
kafka_service/funasr_consumer.py
View file @
cc524ed
...
@@ -82,8 +82,8 @@ def consume_kafka():
...
@@ -82,8 +82,8 @@ def consume_kafka():
# 消费消息并进行逻辑处理
# 消费消息并进行逻辑处理
try
:
try
:
# 先创建进程池,只复制当前资源
# 先创建进程池,只复制当前资源
multiprocessing
.
set_start_method
(
'spawn'
)
#
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()
# m = multiprocessing.Manager()
# q = m.JoinableQueue()
# q = m.JoinableQueue()
# # 加载大内存变量
# # 加载大内存变量
...
@@ -94,13 +94,13 @@ def consume_kafka():
...
@@ -94,13 +94,13 @@ def consume_kafka():
continue
continue
log
.
info
(
f
"Received message: {message}"
)
log
.
info
(
f
"Received message: {message}"
)
# 处理逻辑
# 处理逻辑
#
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='监视进度'))))
# 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)
# process = multiprocessing.Process(target=funasr_service.handle_process, args=((str(message.value.decode('utf-8'))),),)
# process = multiprocessing.Process(target=funasr_service.handle_process, args=((str(message.value.decode('utf-8'))),),)
# process.start()
# process.start()
print
(
"task handle"
)
print
(
"task handle"
)
...
...
main.py
View file @
cc524ed
...
@@ -18,6 +18,7 @@ from funasr_service import FunasrService
...
@@ -18,6 +18,7 @@ from funasr_service import FunasrService
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
from
mysql_service
import
funasr_db
from
mysql_service
import
funasr_db
from
kafka_service
import
funasr_consumer
from
kafka_service
import
funasr_consumer
import
gc
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
# 将根目录添加到 Python 解释器的搜索路径中
# 将根目录添加到 Python 解释器的搜索路径中
...
@@ -237,6 +238,41 @@ def start_process():
...
@@ -237,6 +238,41 @@ def start_process():
log
.
info
(
f
"process:{process}"
)
log
.
info
(
f
"process:{process}"
)
process
.
start
()
process
.
start
()
def
start_process_kafka
():
process_pool
=
multiprocessing
.
Pool
(
processes
=
2
,
initializer
=
consumer_process_init
)
log
.
info
(
f
"main process_pool1:{process_pool}"
)
process_pool
.
apply_async
(
func
=
funasr_consumer
.
consume_kafka
,
# args=(),
callback
=
consumer_process_callback
,
error_callback
=
consumer_process_error_callback
)
def
consumer_process_init
():
process_name
=
str
(
multiprocessing
.
current_process
()
.
name
)
log
.
info
(
f
"consumer_process_init process_name:{process_name}"
)
# try:
# res = funasr_db.select_process_fail_task(process_name)
# if res is not None:
# data = {"task_id": res[0]["task_id"]}
# message = json.dumps(data).encode('utf-8')
# funasr_service.handle_process(str(message))
# except Exception as e:
# log.error(f"consumer_process_init_error process_name:{process_name}", e)
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))
gc
.
collect
()
def
consumer_process_error_callback
(
err
):
log
.
error
(
f
"consumer_process_error_callback:{err}"
)
gc
.
collect
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
log
.
info
(
"funasr main starting..."
)
log
.
info
(
"funasr main starting..."
)
...
...
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