4

I tried to profiling my program, which is a file downloader. I use 5 QNetworkRequest to enhance transfer speed, they all connect to the same readyRead() slot.

I use QMap to buffer those byte arrays.

When downloading speed reaches, e.g 5 MiB/s, I found CPU costs rises up significantly, nearly 100%, readyRead() was calling 30 times per seconds.

Is there any suggestion to this, e.g can I let QNetworkReply buffer its io device, reduce the amount of signals emitted?

UPDATA

I made some debug output in readyReady(): (reply here was casted from sender())

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

And about 30 output per seconds , each contains 1500 bytes

daisy
  • 22,498
  • 29
  • 129
  • 265

1 Answers1

2

I have one hint after quick look on your code. You're using QByteArray::append member (downloadBuffers) which realocates internal buffer for appended data. If you're able to predict how much data you will store in each download buffer then use QByteArray::reserve with exact amount of data. If you can't you could simply reserve i.e. 1mb and reserve memory progresively 1mb each time your next append will exceed current QByteArray::capacity. You can for example reserve downbufferSize for each buffer. It's a slight optimization, but should give you some time

Kamil Klimek
  • 12,884
  • 2
  • 43
  • 58
  • That's of great help , but , had to ask: what's difference between `resize()` and `reserve()` here , i'm not sure if it's same with C++ STL(Vector) .. document is pretty confusing to me – daisy May 25 '12 at 08:37
  • reserve resizes internal buffer, but keeps QByteArray to think that it has same ammount of data as it had before doing reserve. Resize resizes internal buffer and tells QByteArray that it contains `size` bytes (of uninitialized data) – Kamil Klimek May 25 '12 at 08:39