Bugzilla – Attachment 21667 Details for
Bug 10611
C4::Context->dbh checks if the DB is still running
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 10611: Use mysql_auto_reconnect instead of ping
SIGNED-OFF-Bug-10611-Use-mysqlautoreconnect-instea.patch (text/plain), 3.12 KB, created by
Bernardo Gonzalez Kriegel
on 2013-09-30 17:28:36 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 10611: Use mysql_auto_reconnect instead of ping
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2013-09-30 17:28:36 UTC
Size:
3.12 KB
patch
obsolete
>From 21236c70766334c5cbd3d0631d1bcc94c14cda4f Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 16 Jul 2013 11:53:47 +0200 >Subject: [PATCH] [SIGNED-OFF] Bug 10611: Use mysql_auto_reconnect instead of > ping > >DBD::Mysql provides a mysql_auto_reconnect flag. Using it avoid to do a >ping. > >Benchmarks: > >use Modern::Perl; >use C4::Context; >for ( 1 .. 1000 ) { > $dbh = C4::Context->dbh; >} > >* without this patch on a local DB: >perl t.pl 0,49s user 0,02s system 98% cpu 0,525 total >* without this patch on a remote DB: >perl t.pl 0,52s user 0,05s system 1% cpu 37,358 total >* with this patch on a local DB: >perl t.pl 0,46s user 0,04s system 99% cpu 0,509 total >* with this patch on a remote DB: >perl t.pl 0,49s user 0,02s system 56% cpu 0,892 total > >Testing the auto reconnect: >use Modern::Perl; >use C4::Context; >my $ping = $dbh->ping; >say $ping; >$dbh->disconnect; >$ping = $dbh->ping; >say $ping; > >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Comment: Real improvement. No koha-qa errors > >prove t/db_dependent/Circulation_issuingrules.t produces no error >prove t/db_dependent/Context.t produces no error > >Test >1) dumped Koha DB, load it on a non-local server >2) run sample script whit and without patch, local and remote > >use Modern::Perl; >use C4::Context; >for ( 1 .. 100000 ) { > my $dbh = C4::Context->dbh; >} > >Main difference I note is with remote server >a) without patch >real 0m16.357s >user 0m2.592s >sys 0m2.132s > >b) with patch >real 0m0.259s >user 0m0.240s >sys 0m0.012s > >I think this could be good for DBs placed on >remote servers >--- > C4/Context.pm | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 739a0ec..874a9ae 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -789,16 +789,14 @@ sub _new_Zconn { > # Internal helper function (not a method!). This creates a new > # database connection from the data given in the current context, and > # returns it. >+our $db_driver = 'mysql'; > sub _new_dbh > { > > ## $context >- ## correct name for db_schme >- my $db_driver; >+ ## correct name for db_schme > if ($context->config("db_scheme")){ > $db_driver=db_scheme2dbi($context->config("db_scheme")); >- }else{ >- $db_driver="mysql"; > } > > my $db_name = $context->config("database"); >@@ -824,6 +822,10 @@ sub _new_dbh > $dbh->{RaiseError} = 0; > } > >+ if ( $db_driver eq 'mysql' ) { >+ $dbh->{mysql_auto_reconnect} = 1; >+ } >+ > my $tz = $ENV{TZ}; > if ( $db_driver eq 'mysql' ) { > # Koha 3.0 is utf-8, so force utf8 communication between mySQL and koha, whatever the mysql default config. >@@ -860,8 +862,10 @@ sub dbh > my $self = shift; > my $sth; > >- if (defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { >- return $context->{"dbh"}; >+ if ( defined $db_driver && $db_driver eq 'mysql' && $context->{"dbh"} ) { >+ return $context->{"dbh"}; >+ } elsif ( defined $db_driver && defined($context->{"dbh"}) && $context->{"dbh"}->ping()) { >+ return $context->{"dbh"}; > } > > # No database handle or it died . Create one. >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10611
:
19765
|
20273
|
21264
|
21655
|
21656
|
21657
|
21667
|
21668
|
21669
|
22103