Skip to content

Commit

Permalink
classify command early for latency calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
vazois committed Sep 13, 2024
1 parent e842ca1 commit b8842ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion libs/server/Resp/AdminCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed unsafe partial class RespServerSession : ServerSessionBase
{
private bool ProcessAdminCommands(RespCommand command)
{
hasAdminCommand = true;
containsAdminOrOtherCommand = true;

if (_authenticator.CanAuthenticate && !_authenticator.IsAuthenticated)
{
Expand Down
14 changes: 9 additions & 5 deletions libs/server/Resp/RespServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ internal sealed unsafe partial class RespServerSession : ServerSessionBase
/// </summary>
public IGarnetServer Server { get; set; }

// Track whether the incoming network batch had some admin command
bool hasAdminCommand;
// Track whether the incoming network batch contains commands other than single key or array commands
bool containsAdminOrOtherCommand;

readonly CustomCommandManagerSession customCommandManagerSession;

Expand Down Expand Up @@ -368,10 +368,10 @@ public override int TryConsumeMessages(byte* reqBuffer, int bytesReceived)
{
if (latencyMetrics != null)
{
if (hasAdminCommand)
if (containsAdminOrOtherCommand)
{
latencyMetrics.StopAndSwitch(LatencyMetricsType.NET_RS_LAT, LatencyMetricsType.NET_RS_LAT_ADMIN);
hasAdminCommand = false;
containsAdminOrOtherCommand = false;
}
else
latencyMetrics.Stop(LatencyMetricsType.NET_RS_LAT);
Expand Down Expand Up @@ -403,6 +403,10 @@ private void ProcessMessages()
// On success, readHead is left at the start of the command payload for legacy operators
var cmd = ParseCommand(out bool commandReceived);

// Classify command as non data command
if (storeWrapper.serverOptions.LatencyMonitor)
containsAdminOrOtherCommand |= !cmd.IsDataCommand();

// If the command was not fully received, reset addresses and break out
if (!commandReceived)
{
Expand Down Expand Up @@ -661,7 +665,7 @@ private bool ProcessArrayCommands<TGarnetApi>(RespCommand cmd, ref TGarnetApi st
private bool ProcessOtherCommands<TGarnetApi>(RespCommand command, ref TGarnetApi storageApi)
where TGarnetApi : IGarnetApi
{
hasAdminCommand = true;
containsAdminOrOtherCommand = true;

var success = command switch
{
Expand Down

0 comments on commit b8842ff

Please sign in to comment.