FHEM Forum

FHEM - Entwicklung => FHEM Development => Thema gestartet von: Nestor am 03 Juli 2020, 18:33:21

Titel: Perl 5.32 memory leaks
Beitrag von: Nestor am 03 Juli 2020, 18:33:21
Did anyone else tried Perl v5.32 with Fhem?
I tried updating this week but experienced continuous memory increase so downgraded back to Perl v5.30.3 and everything back to normal.

Perl v5.30.3

DATE / PID / MEM (kilobytes)
Jul 02 01:40:33 301326 148464 141556
Jul 02 19:40:37 301326 148464 141604

Upgrade to 5.32.0

Jul 02 20:00:37 363974 142984 136220
Jul 02 20:20:37 363974 170276 163536
Jul 02 20:40:37 363974 215216 208580
Jul 02 21:00:37 363974 231824 225152

Downgrade to v5.30.3

Jul 02 21:20:37 366798 148324 141364
Jul 03 18:20:41 366798 148324 141432
Titel: Antw:Perl 5.32 memory leaks
Beitrag von: Nestor am 07 November 2020, 21:21:47
I'm curious if anyone else could try running Fhem under 5.32 and also observe continuous memory increase? It's very easy to test different Perl versions with https://perlbrew.pl/

I tried 5.32 again and memory increased over a day from 140MB to 300MB. With 5.30 it keeps steady around 140MB.
Titel: Antw:Perl 5.32 memory leaks
Beitrag von: rudolfkoenig am 08 November 2020, 23:27:15
How do you measure the memory used?

I am doing it with "ps -flC perl", which gives me in column 10 (SZ) the 4kb pages.
According to this number, perl 5.14 initially used 124MB, while perl 5.30 used 63MB, both with exactly the same configuration. I started perl 5.32 about an hour ago, and it grew 0.4MB, from 58.5 to 58.9MB

5.14 grew from 124MB to 144MB in 3 months, this may be due to program parts used later, memory leaks in perl or in FHEM, or all three together.
5.30 grew from 63 to 68 MB in 5 days, when it was replaced with 5.32
Titel: Antw:Perl 5.32 memory leaks
Beitrag von: Nestor am 08 November 2020, 23:48:14
I'm using the attached script to monitor the RAM usage.

The issue is that with 5.30, Fhem stays at ±140MB for months. With 5.32 it doubles every day (until all 8GB RAM exhausted) and OOM. So I guess there must be a leak somewhere, could also be in a CPAN module offcourse.

#!/usr/bin/env bash

# Usage:
# while sleep 1200; do ./get-mem-usage.sh $(cat /var/run/fhem/fhem.pid) | tee -a ~/fhem-mem.log; done
#

set -euo pipefail

declare -r PID=${1:-""}
declare -r TS=$(date +'%b %d %T')

# Verify args
test -z "$PID" && echo "Usage: $0 PID" && exit
test ! -r "/proc/${PID}/status" && echo "Invalid PID: ${PID}" && exit

declare -r PMAP=$(sudo pmap -x ${PID} | tail -n1 | awk '{print $3}')
declare -r PROC=$(grep 'VmRSS' "/proc/${PID}/status" | awk '{print $2}')

echo -e "$TS\t$PID\t$PMAP\t$PROC"
Titel: Antw:Perl 5.32 memory leaks
Beitrag von: rudolfkoenig am 09 November 2020, 09:23:06
I had another 0.2MB growth in the last 10 hours, which I consider normal for "warmup".
Which CPU-architecture are you using? I am on x86_64.

I have no easy method on finding the culprit. It might help to compare the memory areas showed by pmap, dump the ones which are new or resized, and look at the contents. If you are lucky, you can guess from the content which module is involved. I wish we had better methods.
Titel: Antw:Perl 5.32 memory leaks
Beitrag von: Nestor am 09 November 2020, 19:21:58
Hi Rudolf, I will look into debugging with pmap. ;)

I'm also on x86_64 and using Arch Linux (rolling release) so I had some trouble staying on Perl 5.30 which is solved now with PerlBrew.pl. Maybe I'll try again when 5.33 is released.

Thanks for testing!