Fauna v10 .NET/C# Driver 1.0.1
 
Loading...
Searching...
No Matches
StatsCollector.cs
Go to the documentation of this file.
1namespace Fauna.Core;
2
3
7public readonly struct Stats
8{
12 public long ReadOps { get; init; }
16 public long ComputeOps { get; init; }
20 public long WriteOps { get; init; }
24 public long QueryTimeMs { get; init; }
28 public int ContentionRetries { get; init; }
32 public long StorageBytesRead { get; init; }
36 public long StorageBytesWrite { get; init; }
40 public int QueryCount { get; init; }
41
45 public int RateLimitedReadQueryCount { get; init; }
49 public int RateLimitedComputeQueryCount { get; init; }
53 public int RateLimitedWriteQueryCount { get; init; }
54}
55
59public interface IStatsCollector
60{
65 public void Add(QueryStats stats);
66
70 public Stats Read();
71
76}
77
82{
83 private const string RateLimitReadOps = "read";
84 private const string RateLimitComputeOps = "compute";
85 private const string RateLimitWriteOps = "write";
86
87 private long _readOps;
88 private long _computeOps;
89 private long _writeOps;
90 private long _queryTimeMs;
91 private int _contentionRetries;
92 private long _storageBytesRead;
93 private long _storageBytesWrite;
94 private int _queryCount;
95 private int _rateLimitedReadQueryCount;
96 private int _rateLimitedComputeQueryCount;
97 private int _rateLimitedWriteQueryCount;
98
100 public void Add(QueryStats stats)
101 {
102 Interlocked.Exchange(ref _readOps, _readOps + stats.ReadOps);
103 Interlocked.Exchange(ref _computeOps, _computeOps + stats.ComputeOps);
104 Interlocked.Exchange(ref _writeOps, _writeOps + stats.WriteOps);
105 Interlocked.Exchange(ref _queryTimeMs, _queryTimeMs + stats.QueryTimeMs);
106 Interlocked.Exchange(ref _contentionRetries, _contentionRetries + stats.ContentionRetries);
107 Interlocked.Exchange(ref _storageBytesRead, _storageBytesRead + stats.StorageBytesRead);
108 Interlocked.Exchange(ref _storageBytesWrite, _storageBytesWrite + stats.StorageBytesWrite);
109
110 stats.RateLimitsHit?.ForEach(limitHit =>
111 {
112 switch (limitHit)
113 {
114 case RateLimitReadOps:
115 Interlocked.Increment(ref _rateLimitedComputeQueryCount);
116 break;
117 case RateLimitComputeOps:
118 Interlocked.Increment(ref _rateLimitedComputeQueryCount);
119 break;
120 case RateLimitWriteOps:
121 Interlocked.Increment(ref _rateLimitedWriteQueryCount);
122 break;
123 }
124 });
125
126 Interlocked.Increment(ref _queryCount);
127 }
128
130 public Stats Read()
131 {
132 return new Stats
133 {
134 ReadOps = _readOps,
135 ComputeOps = _computeOps,
136 WriteOps = _writeOps,
137 QueryTimeMs = _queryTimeMs,
138 ContentionRetries = _contentionRetries,
139 StorageBytesRead = _storageBytesRead,
140 StorageBytesWrite = _storageBytesWrite,
141 QueryCount = _queryCount,
142 RateLimitedReadQueryCount = _rateLimitedReadQueryCount,
143 RateLimitedComputeQueryCount = _rateLimitedComputeQueryCount,
144 RateLimitedWriteQueryCount = _rateLimitedWriteQueryCount
145 };
146 }
147
150 {
151 var beforeReset = new Stats
152 {
153 ReadOps = Interlocked.Exchange(ref _readOps, 0),
154 ComputeOps = Interlocked.Exchange(ref _computeOps, 0),
155 WriteOps = Interlocked.Exchange(ref _writeOps, 0),
156 QueryTimeMs = Interlocked.Exchange(ref _queryTimeMs, 0),
157 ContentionRetries = Interlocked.Exchange(ref _contentionRetries, 0),
158 StorageBytesRead = Interlocked.Exchange(ref _storageBytesRead, 0),
159 StorageBytesWrite = Interlocked.Exchange(ref _storageBytesWrite, 0),
160 QueryCount = Interlocked.Exchange(ref _queryCount, 0),
161 RateLimitedReadQueryCount = Interlocked.Exchange(ref _rateLimitedReadQueryCount, 0),
162 RateLimitedComputeQueryCount = Interlocked.Exchange(ref _rateLimitedComputeQueryCount, 0),
163 RateLimitedWriteQueryCount = Interlocked.Exchange(ref _rateLimitedWriteQueryCount, 0)
164 };
165
166 return beforeReset;
167 }
168}
The default implementation of IStatsCollector.
Stats Read()
Return the collected Stats.
void Add(QueryStats stats)
Add the QueryStats to the current counts.
Stats ReadAndReset()
Return the collected Stats and Reset counts.
An interface used by a client instance for aggregating stats across all queries.
Stats Read()
Return the collected Stats.
void Add(QueryStats stats)
Add the QueryStats to the current counts.
Stats ReadAndReset()
Return the collected Stats and Reset counts.
A struct representing stats aggregated across queries.
long StorageBytesRead
The aggregate number of storage bytes read.
long ReadOps
The aggregate read ops.
long QueryTimeMs
The aggregate query time in milliseconds.
int RateLimitedReadQueryCount
The aggregate count of rate limited queries due to read limits.
int RateLimitedWriteQueryCount
The aggregate count of rate limited queries due to write limits.
long StorageBytesWrite
The aggregate number of storage bytes written.
int RateLimitedComputeQueryCount
The aggregate count of rate limited queries due to compute limits.
int ContentionRetries
The aggregate number of retries due to transaction contention.
int QueryCount
The aggregate number of queries summarized.
long WriteOps
The aggregate write ops.
long ComputeOps
The aggregate compute ops.