Bug 28416 - Email::Sender::Transport::SMTP is using 10Mo of RAM
Summary: Email::Sender::Transport::SMTP is using 10Mo of RAM
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Jonathan Druart
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks: 28410
  Show dependency treegraph
 
Reported: 2021-05-21 12:08 UTC by Jonathan Druart
Modified: 2022-04-01 10:33 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00


Attachments
Bug 28416: Delay load of Email::Sender::Transport::SMTP (896 bytes, patch)
2021-05-21 12:11 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 28416: Delay load of Email::Sender::Transport::SMTP (959 bytes, patch)
2022-03-22 15:31 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 28416: Delay load of Email::Sender::Transport::SMTP (1.03 KB, patch)
2022-03-25 10:33 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2021-05-21 12:08:24 UTC
Well ok, it's not that much over the ~130Mo the usual library stack, but maybe we should replace the use with a require to load in only when needed?
Comment 1 Jonathan Druart 2021-05-21 12:11:46 UTC
Created attachment 121275 [details] [review]
Bug 28416: Delay load of Email::Sender::Transport::SMTP

As it's taking 10M of RAM
Comment 2 Jonathan Druart 2021-05-21 12:12:59 UTC
Can be tested with

use Memory::Usage;
my $mu = Memory::Usage->new();
$mu->record('Loading');
require Koha::Libraries;
$mu->record('module loaded');
print $mu->report();

I don't think overall it's a good idea to use require, but maybe it's worth here?
Comment 3 David Cook 2021-05-24 01:17:30 UTC
This one is probably especially good to do, since it looks like transport() is often called within a try/catch block anyway.
Comment 4 Tomás Cohen Arazi 2021-11-08 12:39:17 UTC
(In reply to David Cook from comment #3)
> This one is probably especially good to do, since it looks like transport()
> is often called within a try/catch block anyway.

I agree with this assertion. I'd add that we probably don't want this lib loaded on user facing places, as we are leaning towards using the message_queue more often than we do now.
Comment 5 Jonathan Druart 2022-03-22 14:07:21 UTC
So, signoff?
Comment 6 Tomás Cohen Arazi 2022-03-22 15:31:51 UTC
Created attachment 132028 [details] [review]
Bug 28416: Delay load of Email::Sender::Transport::SMTP

As it's taking 10M of RAM

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 7 Tomás Cohen Arazi 2022-03-22 15:33:46 UTC
(In reply to Jonathan Druart from comment #2)
> Can be tested with
> 
> use Memory::Usage;
> my $mu = Memory::Usage->new();
> $mu->record('Loading');
> require Koha::Libraries;
> $mu->record('module loaded');
> print $mu->report();
> 
> I don't think overall it's a good idea to use require, but maybe it's worth
> here?

I tried moving the 'require' to the Koha::Library namespace. As we will probably load the Koha::SMTP::Server object only when we want the transport anyway. But it didn't help :-D

So signing this patch as it is correct passes the QA tests and does the job. For testers:

$ apt install libmemory-usage-perl
Comment 8 Marcel de Rooy 2022-03-25 10:26:39 UTC Comment hidden (obsolete)
Comment 9 Marcel de Rooy 2022-03-25 10:27:53 UTC Comment hidden (obsolete)
Comment 10 Marcel de Rooy 2022-03-25 10:33:43 UTC
Created attachment 132219 [details] [review]
Bug 28416: Delay load of Email::Sender::Transport::SMTP

As it's taking 10M of RAM

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 11 Marcel de Rooy 2022-03-25 10:34:36 UTC
(In reply to Jonathan Druart from comment #2)

> I don't think overall it's a good idea to use require, but maybe it's worth
> here?

Dangerous precedent created ;)
Comment 12 Fridolin Somers 2022-03-25 21:01:41 UTC
Pushed to master for 22.05, thanks to everybody involved 🦄