From de3499024183a0cc969dc512c18682cee966710a Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Wed, 11 Oct 2017 13:17:49 -0700 Subject: [PATCH] Short Circuit message to local connection in Redis (#1009) --- .../RedisHubLifetimeManager.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs index b9463caeab..728d22dafd 100644 --- a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs @@ -182,6 +182,14 @@ namespace Microsoft.AspNetCore.SignalR.Redis var message = new InvocationMessage(GetInvocationId(), nonBlocking: true, target: methodName, arguments: args); + // If the connection is local we can skip sending the message through the bus since we require sticky connections. + // This also saves serializing and deserializing the message! + var connection = _connections[connectionId]; + if (connection != null) + { + return WriteAsync(connection, message); + } + return PublishAsync(_channelNamePrefix + "." + connectionId, message); }