Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ 功能建议 ]执行慢SQL,窗口关掉后,后台进程没停止,建议查询窗口关掉后,杀死archery查询SQL进程,避免SQL一直跑 #911

Closed
dengpixiong opened this issue Oct 13, 2020 · 9 comments
Labels
wontfix This will not be worked on

Comments

@dengpixiong
Copy link

目前遇到的问题/使用障碍

在使用查询功能进行执行SQL,其中执行到比较慢SQL,窗口关掉后,后台进程没停止,慢SQL一直在MYSQL中执行,需人工介入处理,慢SQL一直执行有一定的安全隐患。

希望如何解决/实现它

建议查询窗口关掉后,杀死archery查询SQL进程,避免SQL一直跑

其他信息

如果有其他类似的产品功能或者图片信息,可在此提交

@LeoQuote
Copy link
Collaborator

配置项里有个 max excution time, 可以把这个设置的短一些, 关闭窗口这个, 欢迎提pr

@dengpixiong
Copy link
Author

配置项里有个 max excution time, 可以把这个设置的短一些, 关闭窗口这个, 欢迎提pr

请问max excution time 单位是什么,是SQL上线和查询都能约束么,我的设置是3600,关闭浏览器后,查询SQL可以一直跑5,6小时

@LeoQuote
Copy link
Collaborator

LeoQuote commented Oct 13, 2020

cursorclass = kwargs.get('cursorclass') or MySQLdb.cursors.Cursor
try:
conn = self.get_connection(db_name=db_name)
conn.autocommit(True)
cursor = conn.cursor(cursorclass)
try:
cursor.execute(f"set session max_execution_time={max_execution_time};")
except MySQLdb.OperationalError:
pass
effect_row = cursor.execute(sql)

应该是秒, 但也要你的服务器支持 set session max_execution_time=xxx

只约束查询.

@LeoQuote
Copy link
Collaborator

Archery/sql/query.py

Lines 89 to 101 in 3343a70

max_execution_time = int(config.get('max_execution_time', 60))
# 执行查询语句,并增加一个定时终止语句的schedule,timeout=max_execution_time
if thread_id:
schedule_name = f'query-{time.time()}'
run_date = (datetime.datetime.now() + datetime.timedelta(seconds=max_execution_time))
add_kill_conn_schedule(schedule_name, run_date, instance.id, thread_id)
with FuncTimer() as t:
# 获取主从延迟信息
seconds_behind_master = query_engine.seconds_behind_master
query_result = query_engine.query(db_name, sql_content, limit_num,
schema_name=schema_name,
tb_name=tb_name,
max_execution_time=max_execution_time * 1000)

@dengpixiong
Copy link
Author

我看了一下,是我的数据库实例版本过低,不支持max_execution_time设置,查了没有这个参数,MYSQL 5.7以后支持。谢谢的回复,感谢!

@dengpixiong
Copy link
Author

这个是不是增加个功能,在archery服务器端杀死超时的进程好一点?

@LeoQuote
Copy link
Collaborator

我个人不是很懂数据库这块, mysql 有方法去删除吗? 关闭连接会杀死查询进程吗?

@hhyo
Copy link
Owner

hhyo commented Oct 14, 2020

#125 #302

目前MySQL查询应该是两个都有保留,会有异步任务去终止,也有会话超时时间的设置,具体可以测试一下

@stale
Copy link

stale bot commented Nov 1, 2020

你已经很久没有回复这个issue了,如果没有进一步的信息的话, 会作为不活跃issue关闭, 感谢你对本项目的贡献。
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Nov 1, 2020
@stale stale bot closed this as completed Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants