Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeLyn committed Apr 18, 2019
2 parents 2b968ff + a79b372 commit b2f7768
Show file tree
Hide file tree
Showing 58 changed files with 1,096 additions and 588 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Samples|Average|Median|90% Line|95% Line|99% Line|Min|Max|Error %|Throughput|KB/
250000|54|53|71|73|81|1|120|0.00%|8943.6/sec|1825.4


## Use example
Use the example to refer to another [simple micro-services shop](https://github.com/1100100/MicroServicesShop), using docker orchestration services.

## Docs
See [wiki documentation](https://github.com/ww198643/Uragano/wiki).

12 changes: 11 additions & 1 deletion Uragano.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Uragano.Logging.Log4Net", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Uragano.Logging.NLog", "src\Uragano.Logging.NLog\Uragano.Logging.NLog.csproj", "{2E19A779-21E7-44D2-958A-F8A69D9A71B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Uragano.ZooKeeper", "src\Uragano.ZooKeeper\Uragano.ZooKeeper.csproj", "{5E7B914D-2971-490C-B5B0-0E51A5DB1090}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ServiceDiscovery", "ServiceDiscovery", "{34AD8CBE-3FB3-42DF-B634-6CB5D63E01F2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -121,6 +125,10 @@ Global
{2E19A779-21E7-44D2-958A-F8A69D9A71B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2E19A779-21E7-44D2-958A-F8A69D9A71B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2E19A779-21E7-44D2-958A-F8A69D9A71B6}.Release|Any CPU.Build.0 = Release|Any CPU
{5E7B914D-2971-490C-B5B0-0E51A5DB1090}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E7B914D-2971-490C-B5B0-0E51A5DB1090}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E7B914D-2971-490C-B5B0-0E51A5DB1090}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E7B914D-2971-490C-B5B0-0E51A5DB1090}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -133,7 +141,7 @@ Global
{2D2972E7-583C-438C-8BAA-712BE812BF9B} = {439B6875-5A3E-4238-88B6-93EDA5EBA30E}
{5B55055A-0FE4-4CD4-B7B2-9C7E5F55C461} = {37596B72-254F-41F3-AD1C-F7F421EB5F02}
{359183AC-E5C6-4C21-A58B-B1C0FA694C2A} = {37596B72-254F-41F3-AD1C-F7F421EB5F02}
{AF570339-CD9D-4F22-A8F4-D784A713081A} = {439B6875-5A3E-4238-88B6-93EDA5EBA30E}
{AF570339-CD9D-4F22-A8F4-D784A713081A} = {34AD8CBE-3FB3-42DF-B634-6CB5D63E01F2}
{B69CE08A-5216-4DC7-BE8E-4A3A784DD98D} = {439B6875-5A3E-4238-88B6-93EDA5EBA30E}
{EBCAB686-FA72-42C3-95F9-BB2BC3BA32F3} = {E6A0D073-6D88-4C5C-A244-CDD2AEEFE3CF}
{13CB019F-32D2-48A3-B454-5C103291CE0F} = {231B1341-66EF-4707-8F5F-943E28B350D8}
Expand All @@ -145,6 +153,8 @@ Global
{0E2FEB44-B557-49A7-AB77-EFFB5B779C4D} = {37596B72-254F-41F3-AD1C-F7F421EB5F02}
{9BC4A74F-5ADF-4836-8ABC-92DAF9ADAA20} = {657B1416-1DA3-4B34-B741-4D4991AED4F9}
{2E19A779-21E7-44D2-958A-F8A69D9A71B6} = {657B1416-1DA3-4B34-B741-4D4991AED4F9}
{5E7B914D-2971-490C-B5B0-0E51A5DB1090} = {34AD8CBE-3FB3-42DF-B634-6CB5D63E01F2}
{34AD8CBE-3FB3-42DF-B634-6CB5D63E01F2} = {439B6875-5A3E-4238-88B6-93EDA5EBA30E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {05D6B99B-B158-41D5-A2C2-3C8206CB45B5}
Expand Down
3 changes: 2 additions & 1 deletion samples/GenericHostSample/GenericHostSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
Expand All @@ -30,6 +30,7 @@
<ProjectReference Include="..\..\src\Uragano.Consul\Uragano.Consul.csproj" />
<ProjectReference Include="..\..\src\Uragano.Core\Uragano.Core.csproj" />
<ProjectReference Include="..\..\src\Uragano.Logging.Exceptionless\Uragano.Logging.Exceptionless.csproj" />
<ProjectReference Include="..\..\src\Uragano.ZooKeeper\Uragano.ZooKeeper.csproj" />
<ProjectReference Include="..\Sample.Common\Sample.Common.csproj" />
<ProjectReference Include="..\Sample.Service.Interfaces\Sample.Service.Interfaces.csproj" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions samples/GenericHostSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Uragano.Core;
using Uragano.Logging.Exceptionless;
using Uragano.Remoting.LoadBalancing;
using Uragano.ZooKeeper;

namespace GenericHostSample
{
Expand Down Expand Up @@ -54,6 +55,7 @@ static async Task Main(string[] args)
builder.AddCircuitBreaker();
builder.AddExceptionlessLogger();
builder.AddConsul();
//builder.AddZooKeeper();
});
}).ConfigureLogging((context, builder) =>
Expand Down
13 changes: 11 additions & 2 deletions samples/GenericHostSample/uragano.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Logging": {
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "Information"
"System": "Warning",
"Microsoft": "Warning"
}
},
"AllowedHosts": "*",
Expand All @@ -29,6 +29,15 @@
"meta": null,
"HealthCheckInterval": 10
}
},
"ZooKeeper": {
"Client": {
"ConnectionString": "localhost:2181"
},
"Service": {
"Name": "PersionService",
"Id": null
}
}
},
"Caching": {
Expand Down
2 changes: 0 additions & 2 deletions samples/Sample.Server/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class ValuesController : ControllerBase
{
private IHelloService HelloService { get; }

private IConfigurationBuilder ConfigurationBuilder { get; }

public ValuesController(IHelloService helloService, IServiceProvider serviceProvider)
{
HelloService = helloService;
Expand Down
1 change: 0 additions & 1 deletion samples/Sample.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class Program
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
Console.ReadKey();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
Expand Down
1 change: 1 addition & 0 deletions samples/Sample.Server/Sample.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ProjectReference Include="..\..\src\Uragano.Logging.Exceptionless\Uragano.Logging.Exceptionless.csproj" />
<ProjectReference Include="..\..\src\Uragano.Logging.Log4net\Uragano.Logging.Log4Net.csproj" />
<ProjectReference Include="..\..\src\Uragano.Logging.NLog\Uragano.Logging.NLog.csproj" />
<ProjectReference Include="..\..\src\Uragano.ZooKeeper\Uragano.ZooKeeper.csproj" />
<ProjectReference Include="..\Sample.Service.Interfaces\Sample.Service.Interfaces.csproj" />
</ItemGroup>

Expand Down
7 changes: 4 additions & 3 deletions samples/Sample.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Uragano.Core;
using Uragano.Logging.Exceptionless;
using Uragano.Remoting.LoadBalancing;
using Uragano.ZooKeeper;
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;

namespace Sample.Server
Expand All @@ -31,10 +32,10 @@ public void ConfigureServices(IServiceCollection services)
services.AddUragano(Configuration, builder =>
{
builder.AddClient(LoadBalancing.Polling);
builder.AddClient(LoadBalancing.ConsistentHash);
builder.AddServer();
builder.AddConsul();
builder.AddZooKeeper();
//builder.AddConsul();
builder.AddClientGlobalInterceptor<ClientGlobalInterceptor>();
builder.AddServerGlobalInterceptor<ServerGlobalInterceptor>();
builder.AddExceptionlessLogger();
Expand Down
4 changes: 2 additions & 2 deletions samples/Sample.Server/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"Logging": {
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "Information"
"System": "Warning",
"Microsoft": "Warning"
}
}
}
11 changes: 10 additions & 1 deletion samples/Sample.Server/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Trace"
"Default": "Warning"
}
},
"AllowedHosts": "*",
Expand All @@ -27,6 +27,15 @@
"meta": null,
"HealthCheckInterval": 10
}
},
"ZooKeeper": {
"Client": {
"ConnectionString": "localhost:2181"
},
"Service": {
"Name": "RPC",
"Id": null
}
}
},
"Caching": {
Expand Down
129 changes: 129 additions & 0 deletions src/Uragano.Abstract/AsyncLock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

namespace Uragano.Abstractions
{
public class AsyncLock
{
private object _reentrancy = new object();
private int _reentrances = 0;
//We are using this SemaphoreSlim like a posix condition variable
//we only want to wake waiters, one or more of whom will try to obtain a different lock to do their thing
//so long as we can guarantee no wakes are missed, the number of awakees is not important
//ideally, this would be "friend" for access only from InnerLock, but whatever.
internal SemaphoreSlim _retry = new SemaphoreSlim(0, 1);
//We do not have System.Threading.Thread.* on .NET Standard without additional dependencies
//Work around is easy: create a new ThreadLocal<T> with a random value and this is our thread id :)
private static readonly long UnlockedThreadId = 0; //"owning" thread id when unlocked
internal long _owningId = UnlockedThreadId;
private static int _globalThreadCounter;
private static readonly ThreadLocal<int> _threadId = new ThreadLocal<int>(() => Interlocked.Increment(ref _globalThreadCounter));
//We generate a unique id from the thread ID combined with the task ID, if any
public static long ThreadId => (long)(((ulong)_threadId.Value) << 32) | ((uint)(Task.CurrentId ?? 0));

struct InnerLock : IDisposable
{
private readonly AsyncLock _parent;
#if DEBUG
private bool _disposed;
#endif

internal InnerLock(AsyncLock parent)
{
_parent = parent;
#if DEBUG
_disposed = false;
#endif
}

internal async Task ObtainLockAsync()
{
while (!TryEnter())
{
//we need to wait for someone to leave the lock before trying again
await _parent._retry.WaitAsync();
}
}

internal async Task ObtainLockAsync(CancellationToken ct)
{
while (!TryEnter())
{
//we need to wait for someone to leave the lock before trying again
await _parent._retry.WaitAsync(ct);
}
}

internal void ObtainLock()
{
while (!TryEnter())
{
//we need to wait for someone to leave the lock before trying again
_parent._retry.Wait();
}
}

private bool TryEnter()
{
lock (_parent._reentrancy)
{
Debug.Assert((_parent._owningId == UnlockedThreadId) == (_parent._reentrances == 0));
if (_parent._owningId != UnlockedThreadId && _parent._owningId != AsyncLock.ThreadId)
{
//another thread currently owns the lock
return false;
}
//we can go in
Interlocked.Increment(ref _parent._reentrances);
_parent._owningId = AsyncLock.ThreadId;
return true;
}
}

public void Dispose()
{
#if DEBUG
Debug.Assert(!_disposed);
_disposed = true;
#endif
lock (_parent._reentrancy)
{
Interlocked.Decrement(ref _parent._reentrances);
if (_parent._reentrances == 0)
{
//the owning thread is always the same so long as we are in a nested stack call
//we reset the owning id to null only when the lock is fully unlocked
_parent._owningId = UnlockedThreadId;
if (_parent._retry.CurrentCount == 0)
{
_parent._retry.Release();
}
}
}
}
}

public IDisposable Lock()
{
var @lock = new InnerLock(this);
@lock.ObtainLock();
return @lock;
}

public async Task<IDisposable> LockAsync()
{
var @lock = new InnerLock(this);
await @lock.ObtainLockAsync();
return @lock;
}

public async Task<IDisposable> LockAsync(CancellationToken ct)
{
var @lock = new InnerLock(this);
await @lock.ObtainLockAsync(ct);
return @lock;
}
}
}
15 changes: 15 additions & 0 deletions src/Uragano.Abstract/EnvironmentVariableReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Uragano.Abstractions
{
public class EnvironmentVariableReader
{
public static T Get<T>(string variable, T defaultValue = default)
{
var value = Environment.GetEnvironmentVariable(variable);
if (string.IsNullOrWhiteSpace(value))
return defaultValue;
return (T)Convert.ChangeType(value, typeof(T));
}
}
}
7 changes: 1 addition & 6 deletions src/Uragano.Abstract/ILoadBalancing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace Uragano.Abstractions
{
public interface ILoadBalancing
{
//public static Type Polling = typeof(LoadBalancingPolling);

//public static Type WeightedPolling = typeof(LoadBalancingWeightedPolling);


Task<ServiceNodeInfo> GetNextNode(string serviceName, string serviceRoute, object[] serviceArgs, Dictionary<string, string> serviceMeta);
Task<ServiceNodeInfo> GetNextNode(string serviceName, string serviceRoute, IReadOnlyList<object> serviceArgs, IReadOnlyDictionary<string, string> serviceMeta);
}
}
Loading

0 comments on commit b2f7768

Please sign in to comment.