Force the QAbstractSocket::LowDelayOption for Http2 channel

Reference gRPC channel does this, to disable the Nagle's algorithm
and reduce the latency for the small flow control frames like
WINDOW_UPDATE and PING.

TODO: We should probably allow to opt out this behavior using
QGrpcChannelOptions. See QTBUG-134428.

Task-number: QTBUG-134428
Task-number: QTBUG-133254
Pick-to: 6.8 6.8.3 6.9 6.9.0
Change-Id: I96efac97077c7e527198bae9ca00500629bd4800
Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
This commit is contained in:
Alexey Edelev 2025-03-04 16:27:31 +01:00 committed by Dennis Oberst
parent 56eee95a7c
commit 921212c1f7
1 changed files with 11 additions and 0 deletions

View File

@ -823,6 +823,17 @@ void QGrpcHttp2ChannelPrivate::createHttp2Connection()
Q_ASSERT_X(m_connection == nullptr, "QGrpcHttp2ChannelPrivate::createHttp2Connection",
"Attempt to create the HTTP/2 connection, but it already exists. This situation is "
"exceptional.");
// Nagle's algorithm slows down gRPC communication when frequently sending small utility
// HTTP/2 frames. Since an ACK is not sent until a predefined timeout if the TCP frame is
// not full enough, communication hangs. In our case, this results in a 40ms delay when
// WINDOW_UPDATE or PING frames are sent in a separate TCP frame.
//
// TODO: We should probably allow users to opt out of this using QGrpcChannelOptions,
// see QTBUG-134428.
if (QAbstractSocket *abstractSocket = qobject_cast<QAbstractSocket *>(m_socket.get()))
abstractSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
m_connection = QHttp2Connection::createDirectConnection(m_socket.get(), {});
if (m_connection) {