Fauna v10 .NET/C# Driver 0.2.0-beta
 
Loading...
Searching...
No Matches
StatsCollector.cs
Go to the documentation of this file.
1namespace Fauna;
2
3
4public readonly struct Stats
5{
6 public long ReadOps { get; init; }
7 public long ComputeOps { get; init; }
8 public long WriteOps { get; init; }
9 public long QueryTimeMs { get; init; }
10 public int ContentionRetries { get; init; }
11 public long StorageBytesRead { get; init; }
12 public long StorageBytesWrite { get; init; }
13 public int QueryCount { get; init; }
14
15 public int RateLimitedReadQueryCount { get; init; }
16 public int RateLimitedComputeQueryCount { get; init; }
17 public int RateLimitedWriteQueryCount { get; init; }
18}
19
20public interface IStatsCollector
21{
26 public void Add(QueryStats stats);
27
31 public Stats Read();
32
37}
38
40{
41 private const string RateLimitReadOps = "read";
42 private const string RateLimitComputeOps = "compute";
43 private const string RateLimitWriteOps = "write";
44
45 private long _readOps;
46 private long _computeOps;
47 private long _writeOps;
48 private long _queryTimeMs;
49 private int _contentionRetries;
50 private long _storageBytesRead;
51 private long _storageBytesWrite;
52 private int _queryCount;
53 private int _rateLimitedReadQueryCount;
54 private int _rateLimitedComputeQueryCount;
55 private int _rateLimitedWriteQueryCount;
56
57
58 public void Add(QueryStats stats)
59 {
60 Interlocked.Exchange(ref _readOps, _readOps + stats.ReadOps);
61 Interlocked.Exchange(ref _computeOps, _computeOps + stats.ComputeOps);
62 Interlocked.Exchange(ref _writeOps, _writeOps + stats.WriteOps);
63 Interlocked.Exchange(ref _queryTimeMs, _queryTimeMs + stats.QueryTimeMs);
64 Interlocked.Exchange(ref _contentionRetries, _contentionRetries + stats.ContentionRetries);
65 Interlocked.Exchange(ref _storageBytesRead, _storageBytesRead + stats.StorageBytesRead);
66 Interlocked.Exchange(ref _storageBytesWrite, _storageBytesWrite + stats.StorageBytesWrite);
67
68 stats.RateLimitsHit?.ForEach(limitHit =>
69 {
70 switch (limitHit)
71 {
72 case RateLimitReadOps:
73 Interlocked.Increment(ref _rateLimitedComputeQueryCount);
74 break;
75 case RateLimitComputeOps:
76 Interlocked.Increment(ref _rateLimitedComputeQueryCount);
77 break;
78 case RateLimitWriteOps:
79 Interlocked.Increment(ref _rateLimitedWriteQueryCount);
80 break;
81 }
82 });
83
84 Interlocked.Increment(ref _queryCount);
85 }
86
87 public Stats Read()
88 {
89 return new Stats
90 {
91 ReadOps = _readOps,
92 ComputeOps = _computeOps,
93 WriteOps = _writeOps,
94 QueryTimeMs = _queryTimeMs,
95 ContentionRetries = _contentionRetries,
96 StorageBytesRead = _storageBytesRead,
97 StorageBytesWrite = _storageBytesWrite,
98 QueryCount = _queryCount,
99 RateLimitedReadQueryCount = _rateLimitedReadQueryCount,
100 RateLimitedComputeQueryCount = _rateLimitedComputeQueryCount,
101 RateLimitedWriteQueryCount = _rateLimitedWriteQueryCount
102 };
103 }
104
106 {
107 var beforeReset = new Stats
108 {
109 ReadOps = Interlocked.Exchange(ref _readOps, 0),
110 ComputeOps = Interlocked.Exchange(ref _computeOps, 0),
111 WriteOps = Interlocked.Exchange(ref _writeOps, 0),
112 QueryTimeMs = Interlocked.Exchange(ref _queryTimeMs, 0),
113 ContentionRetries = Interlocked.Exchange(ref _contentionRetries, 0),
114 StorageBytesRead = Interlocked.Exchange(ref _storageBytesRead, 0),
115 StorageBytesWrite = Interlocked.Exchange(ref _storageBytesWrite, 0),
116 QueryCount = Interlocked.Exchange(ref _queryCount, 0),
117 RateLimitedReadQueryCount = Interlocked.Exchange(ref _rateLimitedReadQueryCount, 0),
118 RateLimitedComputeQueryCount = Interlocked.Exchange(ref _rateLimitedComputeQueryCount, 0),
119 RateLimitedWriteQueryCount = Interlocked.Exchange(ref _rateLimitedWriteQueryCount, 0)
120 };
121
122 return beforeReset;
123 }
124}
Stats ReadAndReset()
Return the collected Stats and Reset counts.
Stats Read()
Return the collected Stats.
void Add(QueryStats stats)
Add the QueryStats to the current counts.
void Add(QueryStats stats)
Add the QueryStats to the current counts.
Stats ReadAndReset()
Return the collected Stats and Reset counts.
Stats Read()
Return the collected Stats.
Definition Client.cs:8
Contains statistics related to the execution of a query in the Fauna database.
Definition QueryStats.cs:10
int StorageBytesRead
The amount of data read from storage, in bytes.
Definition QueryStats.cs:45
List< string > RateLimitsHit
The types of operations that were limited or approaching rate limits.
Definition QueryStats.cs:57
int QueryTimeMs
The query processing time in milliseconds.
Definition QueryStats.cs:33
int StorageBytesWrite
The amount of data written to storage, in bytes.
Definition QueryStats.cs:51
int ComputeOps
The number of compute operations consumed by the query.
Definition QueryStats.cs:15
int WriteOps
The number of write operations consumed by the query.
Definition QueryStats.cs:27
int ContentionRetries
The write contention retry count.
Definition QueryStats.cs:39
int ReadOps
The number of read operations consumed by the query.
Definition QueryStats.cs:21
int RateLimitedWriteQueryCount
long StorageBytesWrite
int RateLimitedReadQueryCount
long StorageBytesRead
int RateLimitedComputeQueryCount