Summary: | DBIx::Class Startup speed | ||
---|---|---|---|
Product: | Koha | Reporter: | Jonathan Druart <jonathan.druart> |
Component: | Architecture, internals, and plumbing | Assignee: | Jonathan Druart <jonathan.druart> |
Status: | CLOSED FIXED | QA Contact: | Testopia <testopia> |
Severity: | enhancement | ||
Priority: | P5 - low | CC: | abl, f.demians, gwilliams, tomascohen |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
See Also: |
http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15341 https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=13690 https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=16309 https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=20582 |
||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: | Version(s) released in: | ||
Circulation function: | |||
Bug Depends on: | |||
Bug Blocks: | 15342 | ||
Attachments: |
DBIX call stacks
Bug 15350: Cache loaded DBIx::Class schema classes Bug 15350: Move the import of Koha::Schema to a basic `use` |
Description
Jonathan Druart
2015-12-10 11:55:44 UTC
1 - Already done 2 - We don't load any components at the moment 3 - In Koha::Schema, I have tried to replace __PACKAGE__->load_namespaces; with my $r = [ qw( Accountline Accountoffset ... Zebraqueue ) ]; __PACKAGE__->load_classes({ 'Koha::Schema::Result' => $r}); I have not noticed any gain using the following script use Koha::Database; Koha::Database->new()->schema()->resultset('Discharge'); Always between 0.85 and 0.90 second 4 - Something to try? Created attachment 45606 [details]
DBIX call stacks
This graph show the time spent in DBIx::Class::Schema::load_namespace by a script which does nothing but creating a connection to Koha DB. It take half a second on recent CPU. The question for me is whether the schema creation, which implies creating thousand of classes, is redone each time a Koha page is loaded, or if it's cached under Plack.
Created attachment 48519 [details] [review] Bug 15350: Cache loaded DBIx::Class schema classes This separates the Koha::Schema creation into two stages: 1) The loading of the schemas themselves, which is done upon import of Koha::Database. This requires moving the import of Koha::Schema from an on-demand `require` to just a `use`; most everything in Koha uses C4::Context, which will indirectly end up calling Koha::Database->schema->new anyway, so this was no longer saving anything. 2) The actual database connection, which is done by cloning the schema created above and adding a database connection. Note that this saves time only when a Plack-based Koha needs to create a database connection, which is usually only the case for a new worker. Unscientific timings before patch: * First load of koha2marclinks.pl on a new worker: 0.70 seconds * Each load after: 0.17 seconds After patch: * First load: 0.31 seconds * Each load after: 0.17 seconds (In reply to Jesse Weaver from comment #3) > Created attachment 48519 [details] [review] [review] > Bug 15350: Cache loaded DBIx::Class schema classes > > This separates the Koha::Schema creation into two stages: > > 1) The loading of the schemas themselves, which is done upon import of > Koha::Database. This requires moving the import of Koha::Schema from > an on-demand `require` to just a `use`; most everything in Koha uses > C4::Context, which will indirectly end up calling > Koha::Database->schema->new anyway, so this was no longer saving > anything. Yes, I totally agree. This was previously done when our Plack implementation was not considered stable and we did not want to load the schema everywhere. Now we want. > 2) The actual database connection, which is done by cloning the schema > created above and adding a database connection. I am not sure about this change, the Koha::Schema->connect will load all the classes (see Koha::Schema: 12 __PACKAGE__->load_namespaces;). > Note that this saves time only when a Plack-based Koha needs to create > a database connection, which is usually only the case for a new worker. > > Unscientific timings before patch: > * First load of koha2marclinks.pl on a new worker: 0.70 seconds > * Each load after: 0.17 seconds > > After patch: > * First load: 0.31 seconds > * Each load after: 0.17 seconds Are you sure it's brought by the ->clone call or just the move from require to use? :) Created attachment 48653 [details] [review] Bug 15350: Move the import of Koha::Schema to a basic `use` This moves the import of Koha::Schema from an on-demand `require` to just a `use`; most everything in Koha uses C4::Context, which will indirectly end up calling Koha::Database->schema->new anyway, so this was no longer saving anything. Note that this saves time only when a Plack-based Koha needs to create a database connection, which is usually only the case for a new worker. Unscientific timings before patch: * First load of koha2marclinks.pl on a new worker: 0.70 seconds * Each load after: 0.17 seconds After patch: * First load: 0.31 seconds * Each load after: 0.17 seconds Jonathan, you seem to be right. NYTProf was making me think we needed to do both, but timings suggest otherwise. Jesse, I finally don't think this patch is worth the gain: for the scripts not using Plack (misc/*), they will load of the schema even if it's not needed. (In reply to Jonathan Druart from comment #6) > Jesse, > I finally don't think this patch is worth the gain: for the scripts not > using Plack (misc/*), they will load of the schema even if it's not needed. Maybe it is time to think Plack-wise. Nothing more from here, closing. |