From 5ca79de76c643d54db886d88fa0ed11222b8a05b Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 30 Apr 2024 06:22:52 +0000 Subject: [PATCH] Bug 36721: Add -M Koha::Preload to preload libraries into starman master By preloading common libraries into starman master, we save memory as starman master will share the memory addresses with its starman worker processes. We will also save time because each individual worker won't need to load these common modules. They'll already be done! To test: 0. Don't apply the patch yet 1. In koha-conf.xml, set the plack workers to a high number 2. Restart Plack 3. Note the memory usage using "free -m" 4. Apply the patch 5. Restart Plack using "debian/scripts/koha-plack" 6. Note the memory usage using "free -m" 7. Memory usage should be significantly less (around 1GB with 16 workers) 8. Comparing time is more difficult, but can be done before/after patch using strace, top, or by modifying Koha/REST/V1.pm to output a timestamp at the end of its load. Other ideas are also welcome. --- Koha/Preload.pm | 22 ++++++++++++++++++++++ debian/scripts/koha-plack | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Koha/Preload.pm diff --git a/Koha/Preload.pm b/Koha/Preload.pm new file mode 100644 index 00000000000..37eb1790b8f --- /dev/null +++ b/Koha/Preload.pm @@ -0,0 +1,22 @@ +package Koha::Preload; + +use Modern::Perl; +use Mojo::Base 'Mojolicious'; +use Mojolicious::Plugin::OAuth2; +use Mojolicious::Plugin::OpenAPI; +use Mojolicious::Plugin::OpenAPI::Cors; +use Mojolicious::Plugin::OpenAPI::Security; +use Mojolicious::Plugin::OpenAPI::SpecRenderer; +use Mojolicious::Plugin::RenderFile; +use Net::Netmask; +use Plack::Middleware::ErrorDocument; +use Plack::Middleware::HTTPExceptions; +use Plack::Middleware::Log4perl; +use Plack::Middleware::LogWarn; +use Plack::Middleware::ReverseProxy; +use Plack::Middleware::Static; +use Plack::Response; + +use Koha::Schema; + +1; diff --git a/debian/scripts/koha-plack b/debian/scripts/koha-plack index 6fe18602680..160c21c63cf 100755 --- a/debian/scripts/koha-plack +++ b/debian/scripts/koha-plack @@ -109,7 +109,7 @@ start_plack() STARMAN="/usr/bin/perl -d ${STARMAN}" fi - STARMANOPTS="-M FindBin ${max_requests_and_workers} \ + STARMANOPTS="-M Koha::Preload -M FindBin ${max_requests_and_workers} \ --user=${instance_user} --group ${instancename}-koha \ --pid ${PIDFILE} ${daemonize} ${logging} \ -E ${environment} --socket ${PLACKSOCKET} ${PSGIFILE}" -- 2.39.2