Skip to content

Commit

Permalink
Add byte rate metrics
Browse files Browse the repository at this point in the history
For now it's only added to AsyncCommand.
  • Loading branch information
verdie-g committed Mar 25, 2024
1 parent 38ba28c commit 8a833bf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions AerospikeClient/Async/AsyncConnectionArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ private void SendEvent(SocketAsyncEventArgs args)
return;
}

node.IncrBytesWritten(sent);

if (sent < args.Count)
{
args.SetBuffer(args.Offset + sent, args.Count - sent);
Expand Down Expand Up @@ -172,6 +174,8 @@ private void ReceiveEvent(SocketAsyncEventArgs args)
return;
}

node.IncrBytesRead(received);

if (received < args.Count)
{
args.SetBuffer(args.Offset + received, args.Count - received);
Expand Down
14 changes: 13 additions & 1 deletion AerospikeClient/Async/AsyncNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public sealed class AsyncNode : Node
private readonly new AsyncCluster cluster;
private int asyncConnsOpened;
private int asyncConnsClosed;
private int bytesRead;
private int bytesWritten;

/// <summary>
/// Initialize server node with connection parameters.
Expand Down Expand Up @@ -196,6 +198,16 @@ internal void IncrAsyncConnClosed()
Interlocked.Increment(ref asyncConnsClosed);
}

public void IncrBytesRead(int bytesRead)
{
Interlocked.Increment(ref this.bytesRead);
}

public void IncrBytesWritten(int bytesWritten)
{
Interlocked.Increment(ref this.bytesWritten);
}

public ConnectionStats GetAsyncConnectionStats()
{
int inPool = asyncConnQueue.Count;
Expand All @@ -206,7 +218,7 @@ public ConnectionStats GetAsyncConnectionStats()
{
inUse = 0;
}
return new ConnectionStats(inPool, inUse, asyncConnsOpened, asyncConnsClosed);
return new ConnectionStats(inPool, inUse, asyncConnsOpened, asyncConnsClosed, bytesRead, bytesWritten);
}
}
}
20 changes: 16 additions & 4 deletions AerospikeClient/Cluster/ClusterStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public NodeStats(Node node)
}
else
{
this.asyncStats = new ConnectionStats(0, 0, 0, 0);
this.asyncStats = new ConnectionStats(0, 0, 0, 0, 0, 0);
}
}

Expand Down Expand Up @@ -159,24 +159,36 @@ public sealed class ConnectionStats
/// Total number of node connections closed since node creation.
/// </summary>
public readonly int closed;


/// <summary>
/// Total number of bytes read from that connection.
/// </summary>
public readonly int bytesRead;

/// <summary>
/// Total number of bytes written to that connection.
/// </summary>
public readonly int bytesWritten;

/// <summary>
/// Connection statistics constructor.
/// </summary>
public ConnectionStats(int inPool, int inUse, int opened, int closed)
public ConnectionStats(int inPool, int inUse, int opened, int closed, int bytesRead, int bytesWritten)
{
this.inPool = inPool;
this.inUse = inUse;
this.opened = opened;
this.closed = closed;
this.bytesRead = bytesRead;
this.bytesWritten = bytesWritten;
}

/// <summary>
/// Convert statistics to string.
/// </summary>
public override string ToString()
{
return "" + inUse + ',' + inPool + ',' + opened + ',' + closed;
return "" + inUse + ',' + inPool + ',' + opened + ',' + closed + ',' + bytesRead + ',' + bytesWritten;
}
}
}
2 changes: 1 addition & 1 deletion AerospikeClient/Cluster/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public ConnectionStats GetConnectionStats()
}
inUse += tmp;
}
return new ConnectionStats(inPool, inUse, connsOpened, connsClosed);
return new ConnectionStats(inPool, inUse, connsOpened, connsClosed, -1, -1);
}

public void IncrErrorCount()
Expand Down

0 comments on commit 8a833bf

Please sign in to comment.