Skip to content

Commit

Permalink
WIP: HTTP/2
Browse files Browse the repository at this point in the history
We need Qt 5.9 for HTTP2 because, even if Qt 5.8 already has support
for it, there is some critical bug in the HTTP2 implementation which
make it unusable [ https://codereview.qt-project.org/186050 and
https://codereview.qt-project.org/186066 ]

When using HTTP2, we can use many more parallel network request, this
is especially good for small file handling

Lower the priority of the GET and PUT propagation jobs, so the quota
or selective sync ui PROPFIND will not be blocked by them
  • Loading branch information
ogoffart committed Apr 13, 2017
1 parent 8cb3a77 commit 15ecc6f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/libsync/accessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ QNetworkReply* AccessManager::createRequest(QNetworkAccessManager::Operation op,
if (verb == "PROPFIND") {
newRequest.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml; charset=utf-8"));
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
// only enable HTTP2 with Qt 5.9 because Qt 5.8.0 has too many bugs (only use one connection if the server does not support HTTP2)
newRequest.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true);
#endif

return QNetworkAccessManager::createRequest(op, newRequest, outgoingData);
}

Expand Down
5 changes: 5 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject {
/** Detects a specific bug in older server versions */
bool rootEtagChangesNotOnlySubFolderEtags();

/** True when the server supports HTTP2 */
bool isHttp2Supported() { return _http2Supported; }
void setHttp2Supported(bool value) { _http2Supported = value; };

void clearCookieJar();
void lendCookieJarTo(QNetworkAccessManager *guest);
QString cookieJarPath();
Expand Down Expand Up @@ -225,6 +229,7 @@ protected Q_SLOTS:
QuotaInfo *_quotaInfo;
QSharedPointer<QNetworkAccessManager> _am;
QSharedPointer<AbstractCredentials> _credentials;
bool _http2Supported = false;

/// Certificates that were explicitly rejected by the user
QList<QSslCertificate> _rejectedCertificates;
Expand Down
9 changes: 9 additions & 0 deletions src/libsync/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &inf
return;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
if (auto job = qobject_cast<AbstractNetworkJob *>(sender())) {
if (auto reply = job->reply()) {
_account->setHttp2Supported(
reply->attribute(QNetworkRequest::HTTP2WasUsedAttribute).toBool());
}
}
#endif

// We attempt to work with servers >= 5.0.0 but warn users.
// Check usages of Account::serverVersionUnsupported() for details.

Expand Down
1 change: 0 additions & 1 deletion src/libsync/creds/httpcredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class HttpCredentialsAccessManager : public AccessManager {
req.setSslConfiguration(sslConfiguration);
}


return AccessManager::createRequest(op, req, outgoingData);
}
private:
Expand Down
12 changes: 6 additions & 6 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ int OwncloudPropagator::maximumActiveTransferJob()
// disable parallelism when there is a network limit.
return 1;
}
return qCeil(hardMaximumActiveJob()/2.);
return qMax(3, qCeil(hardMaximumActiveJob()/2.));
}

/* The maximum number of active jobs in parallel */
int OwncloudPropagator::hardMaximumActiveJob()
{
static int max = qgetenv("OWNCLOUD_MAX_PARALLEL").toUInt();
if (!max) {
max = 6; //default (Qt cannot do more anyway)
// TODO: increase this number when using HTTP2
}
return max;
if (max)
return max;
if (_account->isHttp2Supported())
return 20;
return 6; // (Qt cannot do more anyway)
}

PropagateItemJob::~PropagateItemJob()
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void GETFileJob::start() {
req.setRawHeader(it.key(), it.value());
}

req.setPriority(QNetworkRequest::LowPriority); // Long downloads must not block non-propagation jobs.

if (_directDownloadUrl.isEmpty()) {
sendRequest("GET", makeDavUrl(path()), req);
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ void PUTFileJob::start() {
req.setRawHeader(it.key(), it.value());
}

req.setPriority(QNetworkRequest::LowPriority); // Long uploads must not block non-propagation jobs.

if (_url.isValid()) {
sendRequest("PUT", _url, req, _device);
} else {
Expand Down

0 comments on commit 15ecc6f

Please sign in to comment.