The Traveller Subsector Mapper is now no longer running under Hypnotoad but under Systemd.
The main reason I'm doing this is so that systemd can limit the memory available to the app. I'm hoping that this will force Perl to garbage-collect more often and that will show me if I do in fact have memory leaks in the code. I suspect I do, to be honest.
This is what I'm talking about: The web app uses up to 300MiB of RAM. Sure, no problem, there's no need to garbage collect if nobody needs the memory. I still don't like it, though. Probably irrational.
Let's hope this works.
The systemd unit:
[Unit] Description=Traveller After=network.target [Install] WantedBy=multi-user.target [Service] Type=simple WorkingDirectory=/home/alex/farm Restart=always DynamicUser=yes MemoryMax=100M MemoryHigh=80M Environment="PERL5LIB=/home/alex/perl5/perlbrew/perls/perl-5.40.0/lib" ExecStart=/home/alex/perl5/perlbrew/perls/perl-5.40.0/bin/perl \ /home/alex/farm/traveller.pl \ daemon --mode production -l http://localhost:4011
I'm using Perlbrew as my user (alex) so this is the tricky part. This unit guarantees that I'm running the app itself using Perl 5.40.0. In the app, I rely on this:
use Mojolicious::Lite -signatures; use File::Basename; my $dirname = dirname($^X); plugin Mount => {'/traveller' => "$dirname/traveller"}; app->start;
It assumes that App:traveller was installed. It finds the `traveller` script next to the Perl interpreter. If I need to change the Perl version again, I only need to change it in the systemd unit.
The Monit config file no longer needs to know about the Perl version:
check process traveller matching traveller start program = "/usr/bin/systemctl start traveller" stop program = "/usr/bin/systemctl stop traveller" if failed host campaignwiki.org port 443 type tcpssl protocol http and request "/traveller" for 5 cycles then restart if totalmem > 100 MB for 5 cycles then restart
#Administration #Web #Perl #Programming
The systemd service unit:
MemoryMax=300M MemoryHigh=280M
Consequently, for Monit:
if totalmem > 300 MB for 5 cycles then restart
When I tried to leave `MemoryHigh=80M`, memory usage crept up to 81M–82M and then the program crawled to a halt again. So there doesn't seem to be a way to tell it: Yes, you can go up to 300M, but if you're not busy, please go back down to 30M–40M (which is what it takes right after startup). I'm hoping the Linux kernel handles it, I guess.