Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP/2 #5659

Merged
merged 2 commits into from
Jul 17, 2017
Merged

HTTP/2 #5659

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libsync/accessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ QNetworkReply *AccessManager::createRequest(QNetworkAccessManager::Operation op,
qInfo(lcAccessManager) << op << verb << newRequest.url().toString() << "has X-Request-ID" << requestId;
newRequest.setRawHeader("X-Request-ID", requestId);

#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)
if (newRequest.url().scheme() == "https") { // Not for "http": QTBUG-61397
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 @@ -189,6 +189,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 @@ -247,6 +251,7 @@ protected Q_SLOTS:
QuotaInfo *_quotaInfo;
QSharedPointer<QNetworkAccessManager> _am;
QScopedPointer<AbstractCredentials> _credentials;
bool _http2Supported = false;

/// Certificates that were explicitly rejected by the user
QList<QSslCertificate> _rejectedCertificates;
Expand Down
10 changes: 9 additions & 1 deletion src/libsync/connectionvalidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,18 @@ bool ConnectionValidator::setAndCheckServerVersion(const QString &version)
reportResult(ServerVersionMismatch);
return false;
}

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

#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
// Record that the server supports HTTP/2
if (auto job = qobject_cast<AbstractNetworkJob *>(sender())) {
if (auto reply = job->reply()) {
_account->setHttp2Supported(
reply->attribute(QNetworkRequest::HTTP2WasUsedAttribute).toBool());
}
}
#endif
return true;
}

Expand Down
12 changes: 6 additions & 6 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,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;
Copy link
Contributor

@mrow4a mrow4a Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only in download or upload also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That number is for smaller jobs (mkcol, small uploads, small downloads, move, delete)

the maxium amount of longer jobs is still 3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But anyways, it might need some tests probably.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

20 sounds scary :-) let's see if the servers can handle it.. @DeepDiver1975 @PVince81 @butonic

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 @@ -118,6 +118,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 @@ -79,6 +79,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
2 changes: 1 addition & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ void SyncEngine::startSync()
_discoveryMainThread->setParent(this);
connect(this, SIGNAL(finished(bool)), _discoveryMainThread, SLOT(deleteLater()));
qCInfo(lcEngine) << "Server" << account()->serverVersion()
<< QString("rootEtagChangesNotOnlySubFolderEtags=%1").arg(account()->rootEtagChangesNotOnlySubFolderEtags());
<< (account()->isHttp2Supported() ? "Using HTTP/2" : "");
if (account()->rootEtagChangesNotOnlySubFolderEtags()) {
connect(_discoveryMainThread, SIGNAL(etag(QString)), this, SLOT(slotRootEtagReceived(QString)));
} else {
Expand Down