[英]Rails upgrade to 5.2.3 causing "Mysql2::Error: Too many connections"
We're nearly done with our upgrade from Rails 4.2.11.1 to Rails 5.2.3.我们几乎完成了从 Rails 4.2.11.1 到 Rails 5.2.3 的升级。 All tests pass locally and no problems are encountered when running the app locally.
所有测试都在本地通过,在本地运行应用程序时不会遇到任何问题。 On staging (and our failed attempt at updating production) we encounter a very strange error where the number of connections to our database grows and grows until the app becomes unresponsive.
在登台(以及我们更新生产的失败尝试)时,我们遇到了一个非常奇怪的错误,即与数据库的连接数不断增长,直到应用程序无响应为止。
The problem is seen sporadically on staging (hard to reproduce), but very consistent in our production environment.该问题在暂存时偶尔会出现(难以重现),但在我们的生产环境中非常一致。 I think the main difference is the amount of traffic, since our staging servers are only used for our testing whereas the production environment was receiving traffic from several thousand users.
我认为主要区别在于流量,因为我们的临时服务器仅用于我们的测试,而生产环境接收来自数千个用户的流量。 I'm attempting to do some load testing on staging to recreate the issue so that we have a chance of pinpointing the problem, but for now we're at a loss as to why this is happening.
我正在尝试对暂存进行一些负载测试以重现问题,以便我们有机会查明问题,但现在我们不知道为什么会发生这种情况。
It's like the code is not reusing already established connections to the database each time it needs one, and instead creates a new one, uses it once (presumably), and then forgets about it.就像代码没有在每次需要时重用已经建立的数据库连接,而是创建一个新连接,使用一次(大概),然后忘记它。 Has anyone else experienced a problem like this?
有没有其他人遇到过这样的问题? We would really appreciate any help or insight anyone can provide.
我们非常感谢任何人可以提供的任何帮助或见解。
Our specific software versions are listed below:我们的具体软件版本如下:
Gemfile文件
source 'http://rubygems.org'
ruby '2.6.5'
gem 'nokogiri'
gem 'rails', '5.2.3'
gem 'rake'
gem 'mysql2'
gem 'mini_magick'
gem 'liquid', '~> 3.0.1'
gem 'httparty'
gem 'mime-types', '>=1.16', require: 'mime/types'
gem 'oauth'
gem 'oauth2', '~> 1.4'
gem 'roxml'
gem 'sax-machine'
gem 'googlecharts', '1.6.7', require: 'gchart'
gem 'rubyzip', '~> 1.2.1', require: 'zip'
gem 'ruby-openid'
gem 'RedCloth', '~> 4.2.9'
gem 'scoped_search', '~> 4.1.3'
gem 'wicked_pdf', '~> 1.1.0'
gem 'wkhtmltopdf-binary-edge', '~> 0.12.4.0'
gem 'devise'
gem 'devise-encryptable'
gem 'paperclip'
gem 'aws-sdk'
gem 'whois', '~> 2.0.4'
gem 'validates_timeliness'
gem 'will_paginate'
gem 'escape_utils'
gem 'acts_as_list'
gem 'acts_as_paranoid'
gem 'prawn', '~> 2.2.2'
gem 'prawn-table', '~> 0.2.2'
gem 'net-dns', '~> 0.6.1'
gem 'in_place_editing', '~> 1.1.2'
gem 'aasm', '~> 3.0.26'
gem 'dynamic_form', '~> 1.1.4'
gem 'delayed_job_active_record', '~> 4.1', '>= 4.1.2'
gem 'daemons'
gem 'carmen-rails', github: 'jim/carmen-rails'
gem 'dalli'
gem 'Ascii85', '1.0.1'
gem 'rinku', require: 'rails_rinku'
gem 'jquery-rails'
gem 'sass-rails'
gem 'compass-rails', '3.0.2'
gem 'compass-rgbapng', '0.2.1', require: 'rgbapng'
gem 'fancy-buttons', '~> 1.1.1'
gem 'haml-rails'
gem 'haml'
gem 'slim-rails'
gem 'coffee-rails'
gem 'uglifier', '~> 2.3.1'
gem 'holidays', '~> 1.0.5'
gem 'rack-utf8_sanitizer'
gem 'autoprefixer-rails'
gem 'loofah'
gem 'yajl-ruby', require: 'yajl'
gem 'gretel'
gem 'crack'
gem 'lhm'
gem 'twilio-ruby'
gem 'open_uri_redirections'
gem 'godaddy-api', '~> 0.1.0'
gem 'html_truncator', '~> 0.4.1'
gem 'acme-client'
gem 'net-ssh'
gem 'mustache', "~> 1.0"
gem 'net-sftp', '~> 2.1', '>= 2.1.2'
gem 'activeresource'
gem 'geokit', '~> 1.13.1'
gem 'fomo', '~> 0.1.0'
gem 'nameable', '~> 1.1'
gem 'xmlrpc'
gem 'activemodel-serializers-xml'
gem 'airbrake', '~> 9.4', '>= 9.4.5'
1) check max_connections variable and see if it's consistent with number of connections in your productions environement 1) 检查 max_connections 变量,看看它是否与您的生产环境中的连接数一致
mysql> SHOW VARIABLES LIKE 'max_connections';
2) reduce the wait for timeout connections at database.yml 2)减少在database.yml等待超时连接
3) check active record connection pool settings 3)检查活动记录连接池设置
https://devcenter.heroku.com/articles/concurrency-and-database-connections#connection-pool https://devcenter.heroku.com/articles/concurrency-and-database-connections#connection-pool
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.