徒然さめざめ

思ったことを思ったときに思ったように

スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

コネクションプールのconnectionsを消すには

気になって調べてみたっていうかソースを見れば書いてあった。

disconnect!

# Disconnects all connections in the pool, and clears the pool.
def disconnect!
@reserved_connections.each do |name,conn|
checkin conn
end
@reserved_connections = {}
@connections.each do |conn|
conn.disconnect!
end
@connections = []
end

とか
clear_reloadable_connections!

# Clears the cache which maps classes
def clear_reloadable_connections!
@reserved_connections.each do |name, conn|
checkin conn
end
@reserved_connections = {}
@connections.each do |conn|
conn.disconnect! if conn.requires_reloading?
end
@connections = []
end

を使うといい。


>> Foo.first
checkout
5
0
=> #<Foo id: 1, name: nil, bar_id: nil, f_test: nil, created_at: "2009-12-03 07:24:20", updated_at: "2009-12-03 07:24:20">
>> pp ActiveRecord::Base.connection_pool
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0xb7814aa4
@checked_out=
[#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb76c60e4
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"},
@connection=#<Mysql:0xb76c6a30>,
@connection_options=[nil, "root", "", "db_test", nil, nil],
@last_verification=0,
@logger=
#<ActiveSupport::BufferedLogger:0xb79a96bc
@auto_flushing=1,
@buffer={},
@guard=#<Mutex:0xb7999604>,
@level=0,
@log=#<File:/home/ohshima/dbtest/log/development.log>>,
@query_cache_enabled=false,
@quoted_column_names={"foos"=>"`foos`"},
@quoted_table_names={"foos"=>"`foos`"},
@runtime=0.31590461730957>],
@connection_mutex=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@connections=
[#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb76c60e4
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"},
@connection=#<Mysql:0xb76c6a30>,
@connection_options=[nil, "root", "", "db_test", nil, nil],
@last_verification=0,
@logger=
#<ActiveSupport::BufferedLogger:0xb79a96bc
@auto_flushing=1,
@buffer={},
@guard=#<Mutex:0xb7999604>,
@level=0,
@log=#<File:/home/ohshima/dbtest/log/development.log>>,
@query_cache_enabled=false,
@quoted_column_names={"foos"=>"`foos`"},
@quoted_table_names={"foos"=>"`foos`"},
@runtime=0.31590461730957>],
@queue=
#<MonitorMixin::ConditionVariable:0xb7814a2c
@monitor=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@waiters=[]>,
@reserved_connections=
{-604266278=>
#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb76c60e4
@config=
{:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"},
@connection=#<Mysql:0xb76c6a30>,
@connection_options=[nil, "root", "", "db_test", nil, nil],
@last_verification=0,
@logger=
#<ActiveSupport::BufferedLogger:0xb79a96bc
@auto_flushing=1,
@buffer={},
@guard=#<Mutex:0xb7999604>,
@level=0,
@log=#<File:/home/ohshima/dbtest/log/development.log>>,
@query_cache_enabled=false,
@quoted_column_names={"foos"=>"`foos`"},
@quoted_table_names={"foos"=>"`foos`"},
@runtime=0.31590461730957>},
@size=5,
@spec=
#<ActiveRecord::Base::ConnectionSpecification:0xb7868bf4
@adapter_method="mysql_connection",
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"}>,
@timeout=5>
=> nil

>> pp ActiveRecord::Base.connection_pool.clear_reloadable_connections!
[]
=> nil
>> pp ActiveRecord::Base.connection_pool
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0xb7814aa4
@checked_out=[],
@connection_mutex=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@connections=[],
@queue=
#<MonitorMixin::ConditionVariable:0xb7814a2c
@monitor=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@waiters=[]>,
@reserved_connections={},
@size=5,
@spec=
#<ActiveRecord::Base::ConnectionSpecification:0xb7868bf4
@adapter_method="mysql_connection",
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"}>,
@timeout=5>
=> nil

>> Foo.first
checkout
5
0
=> #<Foo id: 1, name: nil, bar_id: nil, f_test: nil, created_at: "2009-12-03 07:24:20", updated_at: "2009-12-03 07:24:20">
>> pp ActiveRecord::Base.connection_pool.disconnect!
[]
=> nil
>> pp ActiveRecord::Base.connection_pool
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0xb7814aa4
@checked_out=[],
@connection_mutex=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@connections=[],
@queue=
#<MonitorMixin::ConditionVariable:0xb7814a2c
@monitor=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@waiters=[]>,
@reserved_connections={},
@size=5,
@spec=
#<ActiveRecord::Base::ConnectionSpecification:0xb7868bf4
@adapter_method="mysql_connection",
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"}>,
@timeout=5>
=> nil
>> Foo.first
checkout
5
0
=> #<Foo id: 1, name: nil, bar_id: nil, f_test: nil, created_at: "2009-12-03 07:24:20", updated_at: "2009-12-03 07:24:20">
>> pp ActiveRecord::Base.connection_pool
#<ActiveRecord::ConnectionAdapters::ConnectionPool:0xb7814aa4
@checked_out=
[#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb767f298
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"},
@connection=#<Mysql:0xb767fbbc>,
@connection_options=[nil, "root", "", "db_test", nil, nil],
@last_verification=0,
@logger=
#<ActiveSupport::BufferedLogger:0xb79a96bc
@auto_flushing=1,
@buffer={},
@guard=#<Mutex:0xb7999604>,
@level=0,
@log=#<File:/home/ohshima/dbtest/log/development.log>>,
@query_cache_enabled=false,
@quoted_column_names={"foos"=>"`foos`"},
@quoted_table_names={"foos"=>"`foos`"},
@runtime=0.313758850097656>],
@connection_mutex=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@connections=
[#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb767f298
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"},
@connection=#<Mysql:0xb767fbbc>,
@connection_options=[nil, "root", "", "db_test", nil, nil],
@last_verification=0,
@logger=
#<ActiveSupport::BufferedLogger:0xb79a96bc
@auto_flushing=1,
@buffer={},
@guard=#<Mutex:0xb7999604>,
@level=0,
@log=#<File:/home/ohshima/dbtest/log/development.log>>,
@query_cache_enabled=false,
@quoted_column_names={"foos"=>"`foos`"},
@quoted_table_names={"foos"=>"`foos`"},
@runtime=0.313758850097656>],
@queue=
#<MonitorMixin::ConditionVariable:0xb7814a2c
@monitor=
#<Monitor:0xb7814a68
@mon_count=0,
@mon_entering_queue=[],
@mon_owner=nil,
@mon_waiting_queue=[]>,
@waiters=[]>,
@reserved_connections=
{-604266278=>
#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb767f298
@config=
{:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"},
@connection=#<Mysql:0xb767fbbc>,
@connection_options=[nil, "root", "", "db_test", nil, nil],
@last_verification=0,
@logger=
#<ActiveSupport::BufferedLogger:0xb79a96bc
@auto_flushing=1,
@buffer={},
@guard=#<Mutex:0xb7999604>,
@level=0,
@log=#<File:/home/ohshima/dbtest/log/development.log>>,
@query_cache_enabled=false,
@quoted_column_names={"foos"=>"`foos`"},
@quoted_table_names={"foos"=>"`foos`"},
@runtime=0.313758850097656>},
@size=5,
@spec=
#<ActiveRecord::Base::ConnectionSpecification:0xb7868bf4
@adapter_method="mysql_connection",
@config={:database=>"db_test", :adapter=>"mysql", :pool=>5, :user=>"root"}>,
@timeout=5>
=> nil

スポンサーサイト

コメント

コメントの投稿


管理者にだけ表示を許可する

トラックバック

トラックバック URL
http://fmkt.blog65.fc2.com/tb.php/139-e656da44
この記事にトラックバックする(FC2ブログユーザー)

FC2Ad

上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。