如何解决“Mysql2::Error:此连接仍在等待结果” mysql2 和 activerecord 错误
我正在将 activerecord 与 mysql2 一起使用,并且我正在设计一次处理对同一 activerecord 模型/类的 10 个查询。 请注意,我使用严格的 activerecord,而不是直接使用 mysql 查询。
我在 Sinatra 中获取调用,然后使用 activerecord 从数据库获取数据。
我不希望调用被阻塞,因此我使用 mysql2 并且我不想想要使用em同步。
但现在我在后续的同时调用中收到以下消息“Mysql2::Error: This connection is still waiting for a result, after you get the result:”。
我没有与 pool=10
我的类
class User < ActiveRecord::Base
和要调用的代码 建立连接 user.find(:all, :conditions => ["id=?", userid])
mysql2 文档说“要使用 ActiveRecord 驱动程序(带或不带 Rails),您需要做的就是安装这个 gem并将您的database.yml中的适配器设置为“mysql2”,这很简单,对吗?:)”
这正是我从mysql迁移到mysql2时所做的。
为什么我会收到此错误。
Not duplicate of this question with the same title
I am using activerecord with mysql2 and I am designing to handle 10 queries to the same activerecord model/class at a time. Please note I am using strict activerecord and not using mysql queries directly.
I get the calls in Sinatra and then use activerecord to get the data from the DB.
I don't wan't the calls to be blocking so therefore I used mysql2 and I do NOT want to use em-synchrony.
But now I get the following "Mysql2::Error: This connection is still waiting for a result, try again once you have the result:" on subsequent simultanous calls.
I am not establishing connection with pool=10
my class
class User < ActiveRecord::Base
and my code to call
user.find(:all, :conditions => ["id=?", userid])
The mysql2 doc says "To use the ActiveRecord driver (with or without rails), all you should need to do is have this gem installed and set the adapter in your database.yml to "mysql2". That was easy right? :)"
And that is exactly what I have done when I moved from mysql to mysql2.
Why am I getting this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个完整的工作示例:
要运行它,请将文件保存为“config.ru”并在线程模式下以瘦方式运行它:
您可以使用 ab 检查一切是否正常工作,我使用了一个名为 siege 的工具:
Here is a fully working example:
to run it save the file as "config.ru" and run it with thin in threaded mode:
You can use ab to check that everything is working, I used a tool called siege:
您应该使用 ConnectionPool...不知何故,您有 2 个连接处于竞争状态。
我不使用 Sinatra,我使用 Rails,但我遇到了同样的问题并这样解决:
You should use a ConnectionPool... Somehow you have 2 connections in a race condition.
I dont use Sinatra, I use Rails, but I had the same problem and solved it like that:
您必须使用连接池。 mysql2 允许查询是异步的,但您仍然只能通过一个连接一次向 MySQL 发送一个查询。如果您通过一个连接发送多个查询,您将收到等待结果消息。
使用连接池应该没问题。
You have to use a connection pool. mysql2 allows the queries to be async, but you can still only send one query at a time to MySQL through one connection. If you send multiple queries through one connection you get the waiting for results message.
Use a connection pool and you should be fine.