Hi,
Sorry if this post is long, but wanted to make sure I have as much information in the post to help understand my issue..
I have created a B4J Cloud app that I have put in a data centre running on a VPS.
The Server is Linux Ubuntu 16.04 LTS. (64bit)
This server has 768MB of Memory with 15GB SSD Hard Drive.
The Java version running on it is:
First of all, my app is running fine on my development Windows 10 machine (Running in a VM on a Mac)
When my app is running on the Linux VPS it is running out of memory and causing the app to crash.
My app is doing many things, and thought I would create a small test app and help narrow it down to what it could be.
My main app is doing:
- Handling 2 HTTP servers (1 for my front end and one for my backend. I wanted the backend to have a different port to connect with and wanted them both separate from each other)
- WebSocket to allow my B4A app (and eventually for my B4i app) to connect and communicate with it.
- UDP Server
- TCP Socket
I thought it was too much for my VPS so I created a small test app. When I only have the 2 HTTP servers & WebSocket running then it seems to be fine, soon as I add the TCP and UDP sockets and the data starts to come though then it starts to use up the memory.
There are products out in the field that will send UDP packets to my VPS which I need. The same device will also send TCP messages to my server which I also need. Unfortunately I can't change the protocol these products communicate with. (So I am stuck with TCP and UDP)
The UDP socket in my B4J app will listen on a port for the incoming connection and receive the packet. This data is saved to a SQLite database on my VPS. (It only contains ASCII messages - fairly small bits of data)
The TCP socket listens on a different port for incoming data and will log that data in a SQLite database on my VPS. (It only contains ASCII messages - fairly small bits of data)
The TCP socket only ever stays open for 10 seconds after it sends the message. This is closed by the remote device sending the message to my server.
To make sure it's not the data being saved that is causing my issues, in my test app I am not storing anything in the database.
My test app also sends the UDP & TCP messages out to my development PC by a UDP message to I can confirm the data is being received remotely.
I have created a service to run my B4J app on my VPS so that in case the server reboots my app will run again when it boots up. (more on my script I am using here: https://www.b4x.com/android/forum/threads/executable-path-is-not-absolute.91303/#post-577149)
When I run my Service, it starts and I can view the status of the service using the SSH command: systemctl status CloudServer.service
You will notice in the screenshot below that I checked 1 minute after the service had started and it was using 13.9M of memory.
I then checked again approx. 4 minutes later and it was using 24.1M of memory.
I then checked again 13 minutes after it had started and it shows it's using 45.6M of memory.
Then checked again 38 minutes after it had started and it was using 77.0M of memory.
Then checked again 1 hour after it had started and it was using 98.8M of memory.
This is running my test app, which is only listening and receiving TCP and UDP messages. (as per the attached B4J project.)
Although the above might not sound like a lot of memory being used, my main app is also handling the HTTP servers and WebSocket as well. However a lot more memory is being used in that app then my test app as it's filtering the message etc before it saves it to the database.
I guess if I left my test app running overnight, then it will crash by morning as it will run out of memory.
I have left my main app running overnight and it crashed. I attached the error report. (It's in 2 files as I had to split the file in half as it was too big to upload to the forum.)
In my test app (attached), in the Main module I have a sub called SendToDevelopmentPC when a TCP message or UDP message is received I am sending this message to that sub which then sends the message as a UDP message to my development PC over the internet.
I have also attached my test app that I used as per my testing above. Maybe I am doing something wrong?
Sorry if this post is long, but wanted to make sure I have as much information in the post to help understand my issue..
I have created a B4J Cloud app that I have put in a data centre running on a VPS.
The Server is Linux Ubuntu 16.04 LTS. (64bit)
This server has 768MB of Memory with 15GB SSD Hard Drive.
The Java version running on it is:
First of all, my app is running fine on my development Windows 10 machine (Running in a VM on a Mac)
When my app is running on the Linux VPS it is running out of memory and causing the app to crash.
My app is doing many things, and thought I would create a small test app and help narrow it down to what it could be.
My main app is doing:
- Handling 2 HTTP servers (1 for my front end and one for my backend. I wanted the backend to have a different port to connect with and wanted them both separate from each other)
- WebSocket to allow my B4A app (and eventually for my B4i app) to connect and communicate with it.
- UDP Server
- TCP Socket
I thought it was too much for my VPS so I created a small test app. When I only have the 2 HTTP servers & WebSocket running then it seems to be fine, soon as I add the TCP and UDP sockets and the data starts to come though then it starts to use up the memory.
There are products out in the field that will send UDP packets to my VPS which I need. The same device will also send TCP messages to my server which I also need. Unfortunately I can't change the protocol these products communicate with. (So I am stuck with TCP and UDP)
The UDP socket in my B4J app will listen on a port for the incoming connection and receive the packet. This data is saved to a SQLite database on my VPS. (It only contains ASCII messages - fairly small bits of data)
The TCP socket listens on a different port for incoming data and will log that data in a SQLite database on my VPS. (It only contains ASCII messages - fairly small bits of data)
The TCP socket only ever stays open for 10 seconds after it sends the message. This is closed by the remote device sending the message to my server.
To make sure it's not the data being saved that is causing my issues, in my test app I am not storing anything in the database.
My test app also sends the UDP & TCP messages out to my development PC by a UDP message to I can confirm the data is being received remotely.
I have created a service to run my B4J app on my VPS so that in case the server reboots my app will run again when it boots up. (more on my script I am using here: https://www.b4x.com/android/forum/threads/executable-path-is-not-absolute.91303/#post-577149)
When I run my Service, it starts and I can view the status of the service using the SSH command: systemctl status CloudServer.service
You will notice in the screenshot below that I checked 1 minute after the service had started and it was using 13.9M of memory.
I then checked again approx. 4 minutes later and it was using 24.1M of memory.
I then checked again 13 minutes after it had started and it shows it's using 45.6M of memory.
Then checked again 38 minutes after it had started and it was using 77.0M of memory.
Then checked again 1 hour after it had started and it was using 98.8M of memory.
This is running my test app, which is only listening and receiving TCP and UDP messages. (as per the attached B4J project.)
Although the above might not sound like a lot of memory being used, my main app is also handling the HTTP servers and WebSocket as well. However a lot more memory is being used in that app then my test app as it's filtering the message etc before it saves it to the database.
I guess if I left my test app running overnight, then it will crash by morning as it will run out of memory.
I have left my main app running overnight and it crashed. I attached the error report. (It's in 2 files as I had to split the file in half as it was too big to upload to the forum.)
In my test app (attached), in the Main module I have a sub called SendToDevelopmentPC when a TCP message or UDP message is received I am sending this message to that sub which then sends the message as a UDP message to my development PC over the internet.
I have also attached my test app that I used as per my testing above. Maybe I am doing something wrong?