My application :
I'm using openPLC on Paspi 3 as a Modbus RTU to Modbus TCP Gateway
running the blank program
My modbusmaster.cpp has some modifications :
all RTU calls are divided into chunks of 20 registers per call
so that I can read any number of registers
Holding registers can be read via function code 4
Modbus TCP connection :
I have two apps polling data from openplc via Modbus TCP :
app1 is polling 24/7, therefor the PLC log message says :
(Reg3000 is the RTU device)
Device Stromzaehler.Reg3000 is disconnected. Attempting to reconnect...
Setting main thread priority to RT
Locking main thread memory
Server: Listening on port 502
Server: waiting for new client...
Connected to MB device Stromzaehler.Reg3000
Server: Client accepted! Creating thread for the new client ID: 5...
Getting current time
Server: waiting for new client...
Server: Thread created for client ID: 5
If I start only app1 openplc works without any flaws about 3 month or so.
app2 creates and opens a TCP socket, reads the data and then closes the socket for one data poll
and does the same for the next data poll
When I start app2 I see a lot of these messages until openplc stops working :
.......
Server: Thread created for client ID: 6
Server: Client accepted! Creating thread for the new client ID: 7...
Server: waiting for new client...
Server: Thread created for client ID: 7
....
After starting app2 memory usage of openplc increases dramatically until it stops working :
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2369 root -31 0 194320 191896 2896 S 1.7 20.2 0:20.32 openplc
792 root 20 0 76236 20324 5828 S 0.0 2.1 0:27.33 nodejs
What I did so far for debugging :
in /var/log/messages I found this :
"kthreadd invoked oom-killer: gfp_mask=0x26000c0, order=1, oom_score_adj=0"
Looks is if the Raspi runs out of memory, my prime suspect : openplc
Next steps :
Restarting openplc via remote web interface
looking for the PID of nodejs and openplc :
ps ax|fgrep nodejs
ps ax|fgrep openplc
Start top with these PIDs
top -p2200,792
When I start only app1 memory usage of openplc stays at 2,9 %
When I start app2 memory usage increases until openplc is stopped
My conclusion so far :
Looks as if openplc doesn't close and free the memory of a socket when the client closes this socket
I will dig deeper.