Reduce the cost of your readyRead () processor with a high-speed internet connection

I tried to profile my program, which is a file downloader. I use 5 QNetworkRequestto increase the transmission speed, they all connect to the same slot readyRead().

I use QMap to buffer these byte arrays.

When the download speed reaches, for example, 5 MB / s, I found that CPU costs increased significantly, almost 100%, readyRead()caused 30 times per second.

Are there any suggestions for this, for example, can I let QNetworkReply buffer its io device, reduce the number of emitted signals?

UPDATA

I did some debugging output in the readyReady () file: ( replyhere it was cast from the sender ())

qDebug() << "Got: " << reply->readAll().length() << " bytes";

And about 30 outputs per second, each contains 1,500 bytes

+3
source share
1 answer

I have one hint after a quick look at the code. You use QByteArray::appendmember ( downloadBuffers), which implements an internal buffer for added data. If you can predict how much data you will store in each load buffer, use QByteArray::reservewith the exact amount of data. If you cannot, you can simply reserve ie 1mb and reserve memory proportionally to 1mb each time your next application exceeds the current one QByteArray::capacity. You can, for example, reserve downbufferSizefor each buffer. This is a little optimization, but you need some time

+2
source

All Articles