lucabaldini / xpedaq

Data acquisition software for the X-ray polarimetry explorers
GNU General Public License v2.0
0 stars 0 forks source link

xpemon stuck in presence of a high rate of events #106

Closed albertomanfreda closed 8 years ago

albertomanfreda commented 8 years ago

xpemon seems not to be able to deal with a rate of events grater than one every ~5 ms. It seems also to be consuming an unusual amount of memory. The two problems may be connected.

lucabaldini commented 8 years ago

200 Hz would be fine for most of the applications (although I am sure we can do more than that). The memory issue is more serious, and we should get to the bottom of it.

albertomanfreda commented 8 years ago

Ok I may have understood the issue with memory. The UDP socket receiving buffers and the class responsible for reading them (pEventReader) live on a different thread than the GUI and the histograms, using queued SLOT/SIGNAL connections to communicate. That is unavoidable, because we don't want the process of filling and drawing histograms to slow down the flow of input datagrams (also we need the GUI to stay operative during data reading). However, QT always makes deep copies of arguments passed through queued SLOT connections. That means, for example, that when pEventReader loops over a event and, for each pixel, emits a signal with its coordinates and the number of adc counts, those three variables (two doubles and an unsigned int) are copied at least one time (and maybe more) in the memory and stay there until all the SLOTs requesting them are executed. If the filling of the histograms is slower than the incoming flux of events, all these queued calls to SLOT waiting to be executed begin to flood the memory.

albertomanfreda commented 8 years ago

I have managed to improve a bit the performance (speed, memory usage) of the monitor.

albertomanfreda commented 8 years ago

I have realized that is much more efficient to fill the histograms in the same thread where the UDP socket operates. A copy of the histograms (which is used for plotting) is kept in the GUI thread and it is periodically synchronized with the other one. This scheme minimize the quantity of inter-thread communication.

A test with 500 events on my laptop (Ubuntu 14.04) and on one PC in the lab (Windows) has shown no slowing of the application and no data loss up to 1 kHz (and I definitely think we are able to handle an even higher rate). This result is threshold independent.

I am closing the issue.