D
D
Denis2017-07-28 10:56:54
Qt
Denis, 2017-07-28 10:56:54

What architecture to choose for a multi-threaded network application on Qt?

I am developing an application that downloads images from network cameras. Then it processes them. And then, upon request, sends the results (json). Application Developed on Qt, as mat. the library is written in C/C++.
Now I use QThreadPool, or rather its global instance, classes inherited from QObject (for signals and slots) & QRunnable act as workers.
I suppose that with a large number of cameras and data requests, brakes may begin:
1. Due to the constant creation of workers for loading and sending data, which actually differ only in a couple of fields;
2. Due to constant context switching.
And now the question itself:
What is the optimal architecture for such an application, if it is developed on Qt?
PS QNetworkAccessManager is used to download and send data

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ighor July, 2017-07-28
@D3Nd3R

You need to minimize the number of TCP reconnects by creating a socket or QNetworkAccessManager in QRunnable every time you reconnect.
QNetworkAccessManager is not optimal for your task, it is geared towards downloading sites. It has 4 sockets by default and are used in parallel for requests. I advise you to make a primitive implementation of HTTP on QSslSocket / QTcpSocket, the simpler the better.
I doubt that you have 10 thousand cameras there, so the best option is to start a separate QThread for each camera connection, maintain it and get images at intervals. Further, the pointer to the image data is sent to the accumulative QThread, which will return json upon request.

R
res2001, 2017-07-28
@res2001

The architecture depends little on Qt.
If your threads seriously load the processor (by 100%), then there is no point in starting more threads than processor cores - it will not be faster.
Therefore, do a queue and a limited number of threads. Add jobs to the queue, and the threads themselves will extract jobs from it and process them.
For networking, you can try asynchronous I/O.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question