[Development] performance of signal slots across threads

Nguyen Huu Minh HuuMinh.Nguyen at vandewiele.com
Thu Feb 27 12:17:45 CET 2014


Hi,

Thank you for your reply. I will try to make a benchmark, in the meanwhile I will try to explain my situation more clearly.

My first object basically handles TCP communication to a (simulated) hardware device. There are many types of messages, but one of them is data request.
That object then emits a signal, which is connected to the other Object will serves the data.

If I keep the two Objects in separate threads, I get the slow performance but only on Linux (not Windows). 
I have tried timing the execution of the signal and slots itself and that basically takes no time. So I do not think it's the duration of the code itself.
Moreover, I decided to remove the signal slots mechanism and instead let the Object communicate directly with each other via regular function calls across threads and I see a small but negligible performance decrease.
>From this I conclude that the problem probably isn't thread contention.

Once I have a benchmark that can reproduce the problem, I will post it.

Greetings,

Minh

-----Original Message-----
From: Olivier Goffart [mailto:olivier at woboq.com] 
Sent: donderdag 27 februari 2014 11:57
To: development at qt-project.org
Cc: Nguyen Huu Minh
Subject: Re: [Development] performance of signal slots across threads

On Tuesday 25 February 2014 16:22:33 Nguyen Huu Minh wrote:
> Hi,
> 
> I am developing a cross platform application on Windows Xp embedded 
> and on Ubuntu 12.04 using Qt 5.2.1. This application makes use of 
> signal slot communication between QObjects living in different threads 
> (worker and GUI). The separation of threads is needed because one of 
> the QObjects handles the communication to a hardware device, whereas 
> the other one processes data required the hardware and other components.
> 
> My main development platform is Windows and testing there show that 
> everything is fine. However, compiling the same code base on Linux I 
> notice very slow performance on Ubuntu due to the signal slot 
> inter-thread communication. If I use the same code and same QObjects, 
> but this time living in the same thread on Ubuntu, the performance is fine again.
> 
> To give you a rough idea, on Ubuntu inter-thread communication takes 
> ~43s for the test code, intra-thread communication ~7s. On Windows in 
> both case I get around ~6s (give or take).
> 
> I realize that using signal slots entails some overhead, I am just 
> surprised by the amount the overhead it seems to create on Ubuntu and 
> the fact that is overhead is almost non-existent on Windows.
> 
> Can anyone give me some insights as to why this is or 
> solutions/workarounds to this phenomenon?

Hi,

It is hard to tell anything without a concrete example. 
Signals and slots itself is not platform specific, so i don't see why they should have different performances on different patforms. The only difference i can think of would be in the event loop handling.

Is your code under high contention (are both thread busy or are they waiting for each others?)  Maybe it is other parts of your application which is slower?

Perhaps could you provide a benchmark?

--
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org



More information about the Development mailing list