-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2876 from Aaronontheweb/actorpath-performance-imp…
…rovements Actorpath performance improvements
- Loading branch information
Showing
20 changed files
with
342 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using Akka.Actor; | ||
using System.Threading; | ||
|
||
namespace Akka.Remote.Serialization | ||
{ | ||
/// <summary> | ||
/// INTERNAL API | ||
/// </summary> | ||
internal sealed class ActorPathThreadLocalCache : ExtensionIdProvider<ActorPathThreadLocalCache>, IExtension | ||
{ | ||
private readonly ThreadLocal<ActorPathCache> _current = new ThreadLocal<ActorPathCache>(() => new ActorPathCache()); | ||
|
||
public ActorPathCache Cache => _current.Value; | ||
|
||
public override ActorPathThreadLocalCache CreateExtension(ExtendedActorSystem system) | ||
{ | ||
return new ActorPathThreadLocalCache(); | ||
} | ||
|
||
public static ActorPathThreadLocalCache For(ActorSystem system) | ||
{ | ||
return system.WithExtension<ActorPathThreadLocalCache, ActorPathThreadLocalCache>(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// INTERNAL API | ||
/// </summary> | ||
internal sealed class ActorPathCache : LruBoundedCache<string, ActorPath> | ||
{ | ||
public ActorPathCache(int capacity = 1024, int evictAgeThreshold = 600) : base(capacity, evictAgeThreshold) | ||
{ | ||
} | ||
|
||
protected override int Hash(string k) | ||
{ | ||
return FastHash.OfStringFast(k); | ||
} | ||
|
||
protected override ActorPath Compute(string k) | ||
{ | ||
ActorPath actorPath; | ||
if (ActorPath.TryParse(k, out actorPath)) | ||
return actorPath; | ||
return null; | ||
} | ||
|
||
protected override bool IsCacheable(ActorPath v) | ||
{ | ||
return v != null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Threading; | ||
using Akka.Actor; | ||
|
||
namespace Akka.Remote.Serialization | ||
{ | ||
/// <summary> | ||
/// INTERNAL API | ||
/// </summary> | ||
internal sealed class AddressThreadLocalCache : ExtensionIdProvider<AddressThreadLocalCache>, IExtension | ||
{ | ||
public AddressThreadLocalCache() | ||
{ | ||
_current = new ThreadLocal<AddressCache>(() => new AddressCache()); | ||
} | ||
|
||
public override AddressThreadLocalCache CreateExtension(ExtendedActorSystem system) | ||
{ | ||
return new AddressThreadLocalCache(); | ||
} | ||
|
||
private readonly ThreadLocal<AddressCache> _current; | ||
|
||
public AddressCache Cache => _current.Value; | ||
|
||
public static AddressThreadLocalCache For(ActorSystem system) | ||
{ | ||
return system.WithExtension<AddressThreadLocalCache, AddressThreadLocalCache>(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// INTERNAL API | ||
/// </summary> | ||
internal sealed class AddressCache : LruBoundedCache<string, Address> | ||
{ | ||
public AddressCache(int capacity = 1024, int evictAgeThreshold = 600) : base(capacity, evictAgeThreshold) | ||
{ | ||
} | ||
|
||
protected override int Hash(string k) | ||
{ | ||
return FastHash.OfStringFast(k); | ||
} | ||
|
||
protected override Address Compute(string k) | ||
{ | ||
Address addr; | ||
if (ActorPath.TryParseAddress(k, out addr)) | ||
{ | ||
return addr; | ||
} | ||
return Address.AllSystems; | ||
} | ||
|
||
protected override bool IsCacheable(Address v) | ||
{ | ||
return v != Address.AllSystems; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.