PDA

View Full Version : Writing to a file from within a QThread is causing the app to deplete system memory



SpiceWeasel
2nd January 2018, 18:26
I have a threaded application that reads data from a UDP socket in one thread, and then passes that data to two other threads: one for processing one for writing out to a file. (Note: The processing thread does nothing at the moment). All the writing thread does is write the data out to an open file.

When I run the app, it constantly consumes memory and then swap space, until there is none left. The OS then terminates the application.

I don't understand this behavior, can anyone shed any light on this? I've attached the entire source code in a tar file.


PS: I also welcome any comment/critique on my use of QThreads.

ChrisW67
3rd January 2018, 08:46
It does not do that in my environment (Linux 64-bit, GCC 6, Qt 5.7.1). Built code as supplied. Does nothing other than create empty file until a UDP datagram is received. Using netcat sent the 519-byte PRO file as a datagram: 4000 bytes written to file. Repeated: 8000 bytes in file etc.

Are you certain this program is the problem? Is the sender you are testing with also on this machine?

SpiceWeasel
3rd January 2018, 13:21
It does not do that in my environment (Linux 64-bit, GCC 6, Qt 5.7.1). Built code as supplied. Does nothing other than create empty file until a UDP datagram is received. Using netcat sent the 519-byte PRO file as a datagram: 4000 bytes written to file. Repeated: 8000 bytes in file etc.

Are you certain this program is the problem? Is the sender you are testing with also on this machine?

Sorry, I should have provided more detail...

Yes, the sender I am testing with is also running on the same machine. I've attached the code for the sender I use. It's a small C application that generates UDP datagrams in a tight while loop. Note: This sender app is just for testing; in deployment of the main application, the data that it receives is generated on another machine and sent over UDP.

I am running this on a RHEL7 laptop with:
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
QMake version 3.0
Using Qt version 5.5.1 in /opt/Qt5.5.1/5.5/gcc_64/lib


I realize that writing out that much data could be problematic -- but I didn't expect it to cause the system to consume memory they way it does.