From 3d5eaa101d83d2c3ee22b9f788f3c7121fb8d62c Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Tue, 4 Mar 2025 16:27:31 +0100 Subject: [PATCH] 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.9.0 6.8 6.8.3 Change-Id: I96efac97077c7e527198bae9ca00500629bd4800 Reviewed-by: Dennis Oberst (cherry picked from commit 921212c1f78c3a990df7d8e9238b706dd89b2006) Reviewed-by: Qt Cherry-pick Bot --- src/grpc/qgrpchttp2channel.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index 4247bc5a..772d720a 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -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(m_socket.get())) + abstractSocket->setSocketOption(QAbstractSocket::LowDelayOption, 1); + m_connection = QHttp2Connection::createDirectConnection(m_socket.get(), {}); if (m_connection) {