QNetworkReply benchmark: Benchmark a chain of SSL requests
Change-Id: Ic74b4189c5b8e7fc8f86d76973d628c63989d32d Reviewed-on: http://codereview.qt.nokia.com/1010 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
This commit is contained in:
parent
5d9818e7b6
commit
ceceb3796f
@ -469,6 +469,7 @@ private slots:
|
|||||||
void httpDownloadPerformance();
|
void httpDownloadPerformance();
|
||||||
void httpDownloadPerformanceDownloadBuffer_data();
|
void httpDownloadPerformanceDownloadBuffer_data();
|
||||||
void httpDownloadPerformanceDownloadBuffer();
|
void httpDownloadPerformanceDownloadBuffer();
|
||||||
|
void httpsRequestChain();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_qnetworkreply::httpLatency()
|
void tst_qnetworkreply::httpLatency()
|
||||||
@ -739,6 +740,87 @@ void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class HttpsRequestChainHelper : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QList<QNetworkRequest> requestList;
|
||||||
|
|
||||||
|
QElapsedTimer timeOneRequest;
|
||||||
|
QList<qint64> timeList;
|
||||||
|
|
||||||
|
QElapsedTimer globalTime;
|
||||||
|
|
||||||
|
QNetworkAccessManager manager;
|
||||||
|
|
||||||
|
HttpsRequestChainHelper() {
|
||||||
|
}
|
||||||
|
public slots:
|
||||||
|
void doNextRequest() {
|
||||||
|
// all requests done
|
||||||
|
if (requestList.isEmpty()) {
|
||||||
|
QTestEventLoop::instance().exitLoop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qobject_cast<QNetworkReply*>(sender()) == 0) {
|
||||||
|
// first start after DNS lookup, start timer
|
||||||
|
globalTime.start();
|
||||||
|
}
|
||||||
|
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
|
||||||
|
if (reply) {
|
||||||
|
QVERIFY(reply->error() == QNetworkReply::NoError);
|
||||||
|
qDebug() << "time =" << timeOneRequest.elapsed() << "ms";
|
||||||
|
timeList.append(timeOneRequest.elapsed());
|
||||||
|
}
|
||||||
|
|
||||||
|
QNetworkRequest request = requestList.takeFirst();
|
||||||
|
timeOneRequest.restart();
|
||||||
|
reply = manager.get(request);
|
||||||
|
QObject::connect(reply, SIGNAL(sslErrors( const QList<QSslError> &)), reply, SLOT(ignoreSslErrors()));
|
||||||
|
QObject::connect(reply, SIGNAL(finished()), this, SLOT(doNextRequest()));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
void tst_qnetworkreply::httpsRequestChain()
|
||||||
|
{
|
||||||
|
int count = 10;
|
||||||
|
|
||||||
|
QNetworkRequest request(QUrl("https://" + QtNetworkSettings::serverName() + "/fluke.gif"));
|
||||||
|
//QNetworkRequest request(QUrl("https://www.nokia.com/robots.txt"));
|
||||||
|
// Disable keep-alive so we have the full re-connecting of TCP.
|
||||||
|
request.setRawHeader("Connection", "close");
|
||||||
|
|
||||||
|
HttpsRequestChainHelper helper;
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
helper.requestList.append(request);
|
||||||
|
|
||||||
|
// Warm up DNS cache and then immediatly start HTTP
|
||||||
|
QHostInfo::lookupHost(QtNetworkSettings::serverName(), &helper, SLOT(doNextRequest()));
|
||||||
|
//QHostInfo::lookupHost("www.nokia.com", &helper, SLOT(doNextRequest()));
|
||||||
|
|
||||||
|
// we can use QBENCHMARK_ONCE when we find out how to make it really run once.
|
||||||
|
// there is still a warmup-run :(
|
||||||
|
|
||||||
|
//QBENCHMARK_ONCE {
|
||||||
|
QTestEventLoop::instance().enterLoop(40);
|
||||||
|
QVERIFY(!QTestEventLoop::instance().timeout());
|
||||||
|
//}
|
||||||
|
|
||||||
|
qint64 elapsed = helper.globalTime.elapsed();
|
||||||
|
|
||||||
|
qint64 average = (elapsed / count);
|
||||||
|
|
||||||
|
qSort(helper.timeList);
|
||||||
|
qint64 median = helper.timeList.at(5);
|
||||||
|
|
||||||
|
qDebug() << "Total:" << elapsed << " Average:" << average << " Median:" << median;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(tst_qnetworkreply)
|
QTEST_MAIN(tst_qnetworkreply)
|
||||||
|
|
||||||
#include "tst_qnetworkreply.moc"
|
#include "tst_qnetworkreply.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user