You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2021/05/26 20:35:18 UTC
[thrift] branch master updated: THRIFT-5419 Incorrect usage of
thread pool in TThreadPoolAsyncServer may lead to poor performance Client:
netstd Patch: Nathan P Sharp, Jens Geyer
This is an automated email from the ASF dual-hosted git repository.
jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new 9a4802a THRIFT-5419 Incorrect usage of thread pool in TThreadPoolAsyncServer may lead to poor performance Client: netstd Patch: Nathan P Sharp, Jens Geyer
9a4802a is described below
commit 9a4802ab411f1f45b58a8eae015707502e36b8ed
Author: phxnsharp <ns...@phoenix-int.com>
AuthorDate: Fri May 21 23:36:30 2021 +0200
THRIFT-5419 Incorrect usage of thread pool in TThreadPoolAsyncServer may lead to poor performance
Client: netstd
Patch: Nathan P Sharp, Jens Geyer
This closes #2395
---
lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
index 7a5254a..49593cc 100644
--- a/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
+++ b/lib/netstd/Thrift/Server/TThreadPoolAsyncServer.cs
@@ -178,7 +178,7 @@ namespace Thrift.Server
try
{
TTransport client = await ServerTransport.AcceptAsync(cancellationToken);
- ThreadPool.QueueUserWorkItem(this.Execute, client);
+ _ = Task.Run(async () => await ExecuteAsync(client), cancellationToken); // intentionally ignoring retval
}
catch (TaskCanceledException)
{
@@ -219,11 +219,11 @@ namespace Thrift.Server
/// threadContext will be a TTransport instance
/// </summary>
/// <param name="threadContext"></param>
- private void Execute(object threadContext)
+ private async Task ExecuteAsync(TTransport client)
{
var cancellationToken = ServerCancellationToken;
- using (TTransport client = (TTransport)threadContext)
+ using (client)
{
ITAsyncProcessor processor = ProcessorFactory.GetAsyncProcessor(client, this);
TTransport inputTransport = null;
@@ -242,12 +242,12 @@ namespace Thrift.Server
//Recover event handler (if any) and fire createContext server event when a client connects
if (ServerEventHandler != null)
- connectionContext = ServerEventHandler.CreateContextAsync(inputProtocol, outputProtocol, cancellationToken).Result;
+ connectionContext = await ServerEventHandler.CreateContextAsync(inputProtocol, outputProtocol, cancellationToken);
//Process client requests until client disconnects
while (!stop)
{
- if (! inputTransport.PeekAsync(cancellationToken).Result)
+ if (! await inputTransport.PeekAsync(cancellationToken))
break;
//Fire processContext server event
@@ -255,10 +255,10 @@ namespace Thrift.Server
//That is to say it may be many minutes between the event firing and the client request
//actually arriving or the client may hang up without ever makeing a request.
if (ServerEventHandler != null)
- ServerEventHandler.ProcessContextAsync(connectionContext, inputTransport, cancellationToken).Wait();
+ await ServerEventHandler.ProcessContextAsync(connectionContext, inputTransport, cancellationToken);
//Process client request (blocks until transport is readable)
- if (!processor.ProcessAsync(inputProtocol, outputProtocol, cancellationToken).Result)
+ if (! await processor.ProcessAsync(inputProtocol, outputProtocol, cancellationToken))
break;
}
}
@@ -274,7 +274,7 @@ namespace Thrift.Server
//Fire deleteContext server event after client disconnects
if (ServerEventHandler != null)
- ServerEventHandler.DeleteContextAsync(connectionContext, inputProtocol, outputProtocol, cancellationToken).Wait();
+ await ServerEventHandler.DeleteContextAsync(connectionContext, inputProtocol, outputProtocol, cancellationToken);
}
finally