通过MySQL Client用命令:show processlist发现数据库连接数量一直居高不下,轻轻松松就上2k+的连接。通过读Rails框架的connection_pool.rb文件代码,发现在各模型中用establish_connection连接数据库会造成很大的问题。文件中类ConnectionHandler的establish_connection方法代码如下:Ruby代码 def establish_connection(name, spec) @connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec) end def establish_connection(name, spec)
@connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
#举个例子,分段函数的处理puts "Please input x:" #输出一些文字
x = gets #等待用户用键盘输入信息
if x<2 #以下是判断输入信息及根据输入信息进行引导
y = x+4
else
y = 2*x
end
puts "The result is:#{y}"#输出结果