QNetworkAccessManager::put is too slow with non empty data
-
I'm writing small programm like ab to test my small rest web service. My app can produce about 200-300 request per second, but ab could about 8k-9k (on the same machine). After small investigation I found the issue - if I use empty QByteArray it works fast. Here is code:
// simplesender.h #ifndef SIMPLESENDER_H #define SIMPLESENDER_H #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> #include <QQueue> #include <QObject> class SimpleSender : public QObject { Q_OBJECT public: explicit SimpleSender(QObject *parent = 0) { connect(&qnam, &QNetworkAccessManager::finished, this, &SimpleSender::slFinished); url = QUrl("http://localhost:8080"); m_in_progress = 0; sendHttpRequest(); } private slots: void slFinished(QNetworkReply *reply) { QByteArray b = reply->readAll(); Q_UNUSED(b); m_in_progress--; sendHttpRequest(); reply->deleteLater(); } private: int m_in_progress; QUrl url; QNetworkAccessManager qnam; void sendHttpRequest() { while (m_in_progress < 10) { QNetworkRequest r(url); QByteArray bb = QByteArray("t"); // with this line 200 r/s //QByteArray bb; // with this line 8k r/s qnam.put(r, bb); m_in_progress++; } } }; #endif // SIMPLESENDER_H
in main.cpp
#include <simplesender.h> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); SimpleSender hs(&a); return a.exec(); }
to be short:
with this code 200 r/sQByteArray bb = QByteArray("t"); // with this line 200 r/s qnam.put(r, bb);
with this code 8000 r/s
QByteArray bb; // with this line 8k r/s qnam.put(r, bb);
My question is how to improve performance.
[Moved to "General and desktop" ~kshegunov]
-
Hi @KoVadim,
Just to rule out the obvious, how sure are you that its the client code, and not the server that's slower when you set the data? ie it could be that whatever is serving
http://localhost:8080
responds slower when it receives"t"
instead of empty content?Cheers.
-
@Paul-Colby
I don't think so. I tested it withab -u put.txt -T text/plain -c 100 -n 10000 "http://localhost:8080/"
where put.txt contains one char. BTW, now instead of my server I use just bare nginx with next configdav_methods PUT; location = / { echo 'ok'; }
-
@KoVadim said in QNetworkAccessManager::put is too slow with non empty data:
I tested it with ab
Great! :)
Though to simulate what your Qt code is doing, you should be using
-c 1
(your code is serialising the requests).Out of curiosity, what order of magnitude r/s is
ab
reporting (with-c 1
)? Of course, its would be extremely hard for any client (including Qt-based ones) to matchab
performance, but interesting to know the order-of-magnitude difference. -
test just now:
with -c1 - 7441 r/s,
with -c2 - 13564 r/s,
with -c10 - 16504 r/s
Post 1 of 5