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 e5e8edfb
authored
Mar 22, 2024
by
‘chizw’
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]进程池性能测试
1 parent
5db69d63
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
9 deletions
funasr_service.py
kafka_service/funasr_consumer.py
kafka_service/funasr_producer.py
mysql_service/funasr_db.py
funasr_service.py
View file @
e5e8edf
...
...
@@ -2,6 +2,8 @@ import multiprocessing
import
threading
import
time
from
funasr
import
AutoModel
import
kafka_service.funasr_producer
from
log.logger
import
log
import
json
import
traceback
...
...
@@ -112,6 +114,7 @@ def deal_worker(task_id: str):
funasr_db
.
update_ali_asr_model_res_fail
(
task_id
,
str
(
e
),
traceback
.
format_exc
())
log
.
error
(
f
"Worker error{e}"
)
traceback
.
print_exc
()
kafka_service
.
funasr_producer
.
send_task_id
(
task_id
)
return
{
"Worker error"
:
str
(
e
)}
...
...
kafka_service/funasr_consumer.py
View file @
e5e8edf
...
...
@@ -109,7 +109,7 @@ def consume_kafka():
log
.
info
(
f
"启动consume_kafka Thread name:{threading.current_thread().name}"
)
# 消费消息并进行逻辑处理
try
:
process_pool
=
multiprocessing
.
Pool
(
processes
=
3
)
process_pool
=
multiprocessing
.
Pool
(
processes
=
1
)
for
message
in
consumer_new
:
if
message
is
None
:
continue
...
...
kafka_service/funasr_producer.py
View file @
e5e8edf
...
...
@@ -9,6 +9,7 @@ from mysql_service import funasr_db
# 创建Kafka生产者
producer
=
KafkaProducer
(
bootstrap_servers
=
ConfigInfo
.
kafka_consumer_bootstrap_servers
)
# Kafka集群的地址
# key = b"funasr-key" # 消息的键(可选)
# 关闭生产者
# producer.close()
...
...
@@ -20,16 +21,20 @@ def send_message_analysis(message):
# 等待所有消息发送完成
producer
.
flush
()
def
send_wait_task
():
wait_res
=
funasr_db
.
select_ali_asr_model_wait
()
if
wait_res
is
None
or
isinstance
(
wait_res
,
bool
)
or
len
(
wait_res
)
<
1
:
return
print
(
f
"服务启动推送等待任务:{wait_res}"
)
for
item
in
wait_res
:
task_id
=
item
[
'task_id'
]
data
=
{
"task_id"
:
task_id
}
message
=
json
.
dumps
(
data
)
.
encode
(
'utf-8'
)
producer
.
send
(
ConfigInfo
.
kafka_consumer_analysis_topic
,
message
)
print
(
f
"send success{task_id}"
)
# 等待所有消息发送完成
producer
.
flush
()
\ No newline at end of file
send_task_id
(
item
[
'task_id'
])
def
send_task_id
(
task_id
:
str
):
data
=
{
"task_id"
:
task_id
}
message
=
json
.
dumps
(
data
)
.
encode
(
'utf-8'
)
producer
.
send
(
ConfigInfo
.
kafka_consumer_analysis_topic
,
message
)
print
(
f
"send success{task_id}"
)
# 等待所有消息发送完成
producer
.
flush
()
mysql_service/funasr_db.py
View file @
e5e8edf
...
...
@@ -44,7 +44,7 @@ def update_ali_asr_model_res_fail(task_id: str, exception_msg: str, exception: s
def
select_ali_asr_model_res
(
task_id
:
str
):
select_sql
=
(
f
"select id,task_id,file_url,task_status,output_data from ali_asr_model_res aamr where del_flag = 0 and "
f
"task_id =
%
s;"
)
f
"task_id =
%
s
and exception_limit < 3
;"
)
return
pool
.
select_all
(
select_sql
,
(
task_id
,))
...
...
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