Struct FID
Represents an ultra-efficient 64 bit in-process-wide unique identifier "Fast Id".
The ID is going to wrap-around after at least 2 weeks (19 days).
The ID consists of 3 segments: [timestamp: 24bit][threadseed: 24bit][counter: 16 bit].
This is needed because:
a). FID stays unique after process restarts
b). This design does not use interlock on global seed, but uses thread-static vars which is 10-20 times faster
The timestamp is the number of 100ms intervals elapsed since Jan 1 2015 expressed as a 24 bit unsigned int, which gives 2^24 = 16,777,216 combinations
which covers 19 days (around 2 weeks) at 100 msec resolution, consequently the ID will generate duplicates after this period.
This struct is useful for creating unique IDs for protocol/traffic messages that live for a limited time (no more than 2 weeks).
Caution: This ID does not identify the machine or process, only items within the process, however when a hosting process restarts(i.e. crash or reboot)
the new IDs will not collide with IDs generated right before the crash for at least 14 days (14 day sliding window).
In a parallel test on 6 Core i7 3.2 GHz this class generates 405 million IDs/sec, which is 57 times faster than Guid that only generates 7 million IDs/sec
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Azos
Assembly: Azos.dll
Syntax
[Serializable]
public struct FID : IEquatable<FID>, IDistributedStableHashProvider
Constructors
FID(UInt64)
Creates instance from ULONG value. Use FID.Generate() to create new IDs instead
Declaration
Parameters
Type |
Name |
Description |
System.UInt64 |
id |
|
Fields
ID
Returns 64 bit process-wide unique ID which is unique for up to 2 weeks
Declaration
Field Value
Type |
Description |
System.UInt64 |
|
Methods
Equals(FID)
Declaration
public bool Equals(FID other)
Parameters
Type |
Name |
Description |
FID |
other |
|
Returns
Type |
Description |
System.Boolean |
|
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Boolean |
|
Overrides
System.ValueType.Equals(System.Object)
Generate()
Generates new process-wide unique ID which is unique for up to 2 weeks
Declaration
public static FID Generate()
Returns
GetDistributedStableHash()
Declaration
public ulong GetDistributedStableHash()
Returns
Type |
Description |
System.UInt64 |
|
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type |
Description |
System.Int32 |
|
Overrides
System.ValueType.GetHashCode()
ToFakeGuidTag()
Converts to Guid by copying ID twice - this is used when in correlation in logs to associate multiple messages into topic.
Warning: the returned Guid is a fake one (hence the name), and not really unique pe UUID spec
Declaration
public Guid ToFakeGuidTag()
Returns
Type |
Description |
System.Guid |
|
ToString()
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.ValueType.ToString()
Implements
System.IEquatable<T>
Extension Methods