From ceceb3796fbfdcd944fc7da7c8b2198fca69cb44 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 1 Jul 2011 15:15:21 +0200 Subject: QNetworkReply benchmark: Benchmark a chain of SSL requests Change-Id: Ic74b4189c5b8e7fc8f86d76973d628c63989d32d Reviewed-on: http://codereview.qt.nokia.com/1010 Reviewed-by: Qt Sanity Bot Reviewed-by: Shane Kearns --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index dc06e420fd..d96b110d54 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -469,6 +469,7 @@ private slots: void httpDownloadPerformance(); void httpDownloadPerformanceDownloadBuffer_data(); void httpDownloadPerformanceDownloadBuffer(); + void httpsRequestChain(); }; void tst_qnetworkreply::httpLatency() @@ -739,6 +740,87 @@ void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer() } } + +class HttpsRequestChainHelper : public QObject { + Q_OBJECT +public: + QList requestList; + + QElapsedTimer timeOneRequest; + QList timeList; + + QElapsedTimer globalTime; + + QNetworkAccessManager manager; + + HttpsRequestChainHelper() { + } +public slots: + void doNextRequest() { + // all requests done + if (requestList.isEmpty()) { + QTestEventLoop::instance().exitLoop(); + return; + } + + if (qobject_cast(sender()) == 0) { + // first start after DNS lookup, start timer + globalTime.start(); + } + QNetworkReply *reply = qobject_cast(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 &)), 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) #include "tst_qnetworkreply.moc" -- cgit v1.2.3