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 c26e9f27
authored
Mar 21, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]多进程优化
1 parent
f0cd387e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
11 deletions
funasr_service.py
kafka_service/funasr_consumer.py
funasr_service.py
View file @
c26e9f2
...
...
@@ -115,7 +115,6 @@ def deal_worker(task_id: str):
if
content
!=
""
:
output
.
append
(
model_output
(
spk
,
offset
,
duration
,
content
)
.
to_dict
())
json_output
=
json
.
dumps
(
output
,
ensure_ascii
=
False
)
log
.
debug
(
f
"output:{json_output}"
)
execute_time
=
time
.
perf_counter
()
-
consuming_start_time
funasr_db
.
update_ali_asr_model_res
(
task_id
,
json_output
,
int
((
execute_time
*
1000
)))
log
.
info
(
...
...
kafka_service/funasr_consumer.py
View file @
c26e9f2
...
...
@@ -64,7 +64,6 @@ class MultiThreadKafka(object):
log
.
info
(
f
"启动consume_kafka Thread name:{threading.current_thread().name}"
)
# 消费消息并进行逻辑处理
try
:
process_pool
=
multiprocessing
.
Pool
(
processes
=
2
)
for
message
in
consumer
:
if
message
is
None
:
continue
...
...
@@ -73,12 +72,8 @@ class MultiThreadKafka(object):
f
"""process name:{multiprocessing.current_process()},thread name:{threading.current_thread().name},
Received message value: {message.value}"""
)
# 处理逻辑
start_time
=
time
.
time
()
# funasr_service.handle_process(str(message.value.decode('utf-8')))
process_pool
.
apply_async
(
funasr_service
.
handle_process
,
(
str
(
message
.
value
.
decode
(
'utf-8'
),
)))
funasr_service
.
handle_process
(
str
(
message
.
value
.
decode
(
'utf-8'
)))
print
(
"task handle"
)
end_time
=
time
.
time
()
log
.
info
(
"handle_process耗时:"
+
str
(
end_time
-
start_time
))
except
Exception
as
e
:
traceback
.
print_exc
()
log
.
error
(
"funasr consumer Exception: "
+
str
(
e
))
...
...
@@ -113,6 +108,7 @@ def consume_kafka():
log
.
info
(
f
"启动consume_kafka Thread name:{threading.current_thread().name}"
)
# 消费消息并进行逻辑处理
try
:
process_pool
=
multiprocessing
.
Pool
(
processes
=
2
)
for
message
in
consumer_new
:
if
message
is
None
:
continue
...
...
@@ -120,11 +116,9 @@ def consume_kafka():
log
.
info
(
f
"""process name:{multiprocessing.current_process()},thread name:{threading.current_thread().name},
Received message value: {message.value}"""
)
# 处理逻辑
start_time
=
time
.
time
(
)
funasr_service
.
handle_process
(
str
(
message
.
value
.
decode
(
'utf-8'
)))
# funasr_service.handle_process(str(message.value.decode('utf-8'))
)
process_pool
.
apply_async
(
funasr_service
.
handle_process
,
(
str
(
message
.
value
.
decode
(
'utf-8'
),
)))
print
(
"task handle"
)
end_time
=
time
.
time
()
log
.
info
(
"handle_process耗时:"
+
str
(
end_time
-
start_time
))
except
Exception
as
e
:
traceback
.
print_exc
()
log
.
error
(
"funasr consumer Exception: "
+
str
(
e
))
...
...
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