How do I set the ActiveRecord query timeout for mysql?(如何为 mysql 设置 ActiveRecord 查询超时?)
问题描述
如何在 ActiveRecord 中设置 mysql 查询超时?我希望将其设置为非常短的时间,例如 10-15 毫秒.这是一个 Sinatra ruby 网络应用程序.
How can I set the mysql query timeout in ActiveRecord? I wish to set it to something very short, like 10-15ms. This is for a Sinatra ruby web app.
谢谢.
推荐答案
好吧,看来 mysql_adapter.rb 中的第 29 和 30 行,
Well, it would appear that per these lines 29 and 30 in mysql_adapter.rb,
@connection.options(Mysql::OPT_READ_TIMEOUT, @config[:read_timeout]) if @config[:read_timeout]
@connection.options(Mysql::OPT_WRITE_TIMEOUT, @config[:write_timeout]) if @config[:write_timeout]
只需要在 .yaml 数据库配置文件中添加一个 read_timeout 和 write_timeout 值.
One need simply only add a read_timeout and write_timeout value to the .yaml database config file.
因此,
development:
adapter: mysql
encoding: utf8
database: app_development
pool: 5
username: root
password:
write_timeout: 1
read_timeout: 1
应该可以将读取和写入超时设置为每次 1 秒.不幸的是,这不允许您设置亚秒级超时.
Should do the trick to set read and write timeouts of 1 sec apiece. Unfortunately this does not allow you to set sub-second timeouts.
这篇关于如何为 mysql 设置 ActiveRecord 查询超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为 mysql 设置 ActiveRecord 查询超时?
基础教程推荐
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
