Add large non-ssl, non-compressed WebSocket message sending optimization

This commit is contained in:
Alex Hultman
2023-05-11 11:18:58 +02:00
parent c9724db3cf
commit f6f5a3d6e8
2 changed files with 54 additions and 35 deletions
+19
View File
@@ -105,6 +105,23 @@ public:
/* If we are subscribers and have messages to drain we need to drain them here to stay synced */ /* If we are subscribers and have messages to drain we need to drain them here to stay synced */
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData(); WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();
/* Special path for long sends of non-compressed, non-SSL messages */
if (message.length() >= 16 * 1024 && !compress && !SSL && !webSocketData->subscriber && getBufferedAmount() == 0 && Super::getLoopData()->corkOffset == 0) {
char header[14];
int header_length = (int) protocol::formatMessage<isServer>(header, nullptr, 0, opCode, message.length(), compress, fin);
int written = us_socket_write2(0, (struct us_socket_t *)this, header, header_length, message.data(), (int) message.length());
if (written != header_length + (int) message.length()) {
/* Buffer up backpressure */
if (written > header_length) {
webSocketData->buffer.append(message.data() + written, message.length() - (size_t) written);
} else {
webSocketData->buffer.append(header + written, (size_t) header_length - (size_t) written);
}
}
} else {
if (webSocketData->subscriber) { if (webSocketData->subscriber) {
/* This will call back into us, send. */ /* This will call back into us, send. */
webSocketContextData->topicTree->drain(webSocketData->subscriber); webSocketContextData->topicTree->drain(webSocketData->subscriber);
@@ -149,6 +166,8 @@ public:
} }
} }
}
/* Every successful send resets the timeout */ /* Every successful send resets the timeout */
if (webSocketContextData->resetIdleTimeoutOnSend) { if (webSocketContextData->resetIdleTimeoutOnSend) {
Super::timeout(webSocketContextData->idleTimeoutComponents.first); Super::timeout(webSocketContextData->idleTimeoutComponents.first);