[Bast-commits] r5786 - in DBIx-Class/0.08/trunk/lib/DBIx: .
Class/Manual
solomon at dev.catalyst.perl.org
solomon at dev.catalyst.perl.org
Fri Mar 20 21:41:50 GMT 2009
Author: solomon
Date: 2009-03-20 21:41:49 +0000 (Fri, 20 Mar 2009)
New Revision: 5786
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod
Log:
Add cookbook entry for dealing with runaway prepared statement cache
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod 2009-03-20 20:21:00 UTC (rev 5785)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Manual/Cookbook.pod 2009-03-20 21:41:49 UTC (rev 5786)
@@ -1737,4 +1737,33 @@
syntax to load the appropriate classes there is not a direct alternative
avoiding L<Module::Find|Module::Find>.
+=head1 MEMORY USAGE
+
+=head2 Cached statements
+
+L<DBIx::Class> normally caches all statements with L<< prepare_cached()|DBI/prepare_cached >>.
+This is normally a good idea, but if too many statements are cached, the database may use too much
+memory and may eventually run out and fail entirely. If you suspect this may be the case, you may want
+to examine DBI's L<< CachedKids|DBI/CachedKidsCachedKids_(hash_ref) >> hash:
+
+ # print all currently cached prepared statements
+ print for keys %{$schema->storage->dbh->{CachedKids}};
+ # get a count of currently cached prepared statements
+ my $count = scalar keys %{$schema->storage->dbh->{CachedKids}};
+
+If it's appropriate, you can simply clear these statements, automatically deallocating them in the
+database:
+
+ my $kids = $schema->storage->dbh->{CachedKids};
+ delete @{$kids}{keys %$kids} if scalar keys %$kids > 100;
+
+But what you probably want is to expire unused statements and not those that are used frequently.
+You can accomplish this with L<Tie::Cache> or L<Tie::Cache::LRU>:
+
+ use Tie::Cache;
+ use DB::Main;
+ my $schema = DB::Main->connect($dbi_dsn, $user, $pass, {
+ on_connect_do => sub { tie %{shift->_dbh->{CachedKids}}, 'Tie::Cache', 100 },
+ });
+
=cut
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class.pm 2009-03-20 20:21:00 UTC (rev 5785)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class.pm 2009-03-20 21:41:49 UTC (rev 5786)
@@ -323,6 +323,8 @@
norbi: Norbert Buchmuller <norbi at nix.hu>
+solomon: Jared Johnson <jaredj at nmgi.com>
+
=head1 LICENSE
You may distribute this code under the same terms as Perl itself.
More information about the Bast-commits
mailing list