aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Core/Server.cs
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2016-05-10 15:38:28 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2016-05-10 15:38:28 -0700
commitfc1ed17fdea8ba574586cfc479f77de3b200f1c6 (patch)
tree23342f774b1ee53ba74dd7fbdda188ee5fb7dd59 /src/csharp/Grpc.Core/Server.cs
parent2b2f414dd1cb3d1f72c8f2713e381f1bb260b3f7 (diff)
parent19cd009ec14c1a759fe4d0ef79eb3fab738137ca (diff)
Merge branch 'credentials_refactoring' of github.com:jboeuf/grpc into credentials_refactoring
Diffstat (limited to 'src/csharp/Grpc.Core/Server.cs')
-rw-r--r--src/csharp/Grpc.Core/Server.cs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index 5b61b7f060..d538a4671f 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -48,6 +48,7 @@ namespace Grpc.Core
/// </summary>
public class Server
{
+ const int InitialAllowRpcTokenCount = 10;
static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<Server>();
readonly AtomicCounter activeCallCounter = new AtomicCounter();
@@ -65,7 +66,7 @@ namespace Grpc.Core
readonly TaskCompletionSource<object> shutdownTcs = new TaskCompletionSource<object>();
bool startRequested;
- bool shutdownRequested;
+ volatile bool shutdownRequested;
/// <summary>
/// Create a new server.
@@ -129,7 +130,13 @@ namespace Grpc.Core
startRequested = true;
handle.Start();
- AllowOneRpc();
+
+ // Starting with more than one AllowOneRpc tokens can significantly increase
+ // unary RPC throughput.
+ for (int i = 0; i < InitialAllowRpcTokenCount; i++)
+ {
+ AllowOneRpc();
+ }
}
}
@@ -239,12 +246,9 @@ namespace Grpc.Core
/// </summary>
private void AllowOneRpc()
{
- lock (myLock)
+ if (!shutdownRequested)
{
- if (!shutdownRequested)
- {
- handle.RequestCall(HandleNewServerRpc, environment);
- }
+ handle.RequestCall(HandleNewServerRpc, environment);
}
}
@@ -283,6 +287,8 @@ namespace Grpc.Core
/// </summary>
private void HandleNewServerRpc(bool success, BatchContextSafeHandle ctx)
{
+ Task.Run(() => AllowOneRpc());
+
if (success)
{
ServerRpcNew newRpc = ctx.GetServerRpcNew(this);
@@ -290,11 +296,9 @@ namespace Grpc.Core
// after server shutdown, the callback returns with null call
if (!newRpc.Call.IsInvalid)
{
- Task.Run(async () => await HandleCallAsync(newRpc)).ConfigureAwait(false);
+ HandleCallAsync(newRpc); // we don't need to await.
}
}
-
- AllowOneRpc();
}
/// <summary>