RestClient.Execute() is extremely slow compared to RestClient.ExecuteAsync().Result
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- csharp
调研方向
首先跟踪 RestClient.Execute() 和 RestClient.ExecuteAsync() 入口点,并在 .NET 8 上使用提供的 Parallel.For 示例重现时间差异。比较它们在并行使用下的同步执行路径,然后验证等效调用具有相当的性能,并且报告的延迟已得到解决。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
RestClient.Execute() is extremely slow compared to RestClient.ExecuteAsync().Result, when called in a parallel setting, even though both are synchronous.
To Reproduce
private class CustomInterceptor : Interceptor
{
public override ValueTask BeforeDeserialization ( RestResponse response, CancellationToken cancellationToken )
{
response.ContentType = ContentTypes.application_json;
return ValueTask.CompletedTask;
}
}
static void Test02 ()
{
//
const int total = 100;
int width = ( int ) Math.Ceiling( Math.Log10( total ) );
( int, TimeSpan )[] elapsed = new ( int, TimeSpan )[total];
//
RestResponse Execute ( RestClient c, string resource, Method method, Action<RestRequest> callback )
{
//
RestRequest i;
RestResponse o;
//
if ( c == null )
throw new ArgumentNullException( nameof( c ) );
i = new RestRequest( resource, method );
callback?.Invoke( i );
i.Interceptors = [];
i.Interceptors.Add( new CustomInterceptor() );
o = c.Execute( i );
return o;
}
void Test ( int i )
{
//
Stopwatch watch;
//
static void Add ( RestRequest t )
{
t.AddHeader( HTTPHeaders.Content_Type, ContentTypes.application_json );
}
watch = Stopwatch.StartNew();
using ( var c = new RestClient( some server ) )
Execute( c, "", Method.Post, Add );
watch.Stop();
elapsed[i] = ( i, watch.Elapsed );
}
Parallel.For( 0, total, Test );
////
Array.Sort( elapsed, ( x, y ) => y.Item2.CompareTo( x.Item2 ) );
for ( int i = 0; i < total; i++ )
Console.WriteLine( $@"{elapsed[i].Item1.ToString().PadLeft( width )} => {elapsed[i].Item2:mm\:ss\.fff}" );
}
If you use the above code, which uses c.Execute( i ), to communicate to a server, there will be very long delays (up to roughly 10 s). If you replace c.Execute( i ) with c.ExecuteAsync( i ).Result, the time is reduced to just roughly 1 s.
Expected behavior
Since both RestClient.Execute() and RestClient.ExecuteAsync().Result are synchronous, both should have the exact same performance.
Desktop
- OS: Windows 11
- .NET 8.0
- Version 114.0.0
- 主要语言
- C#
- 星标
- 9.8k
- 派生
- 2.3k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
restsharp/RestSharp 的其他 Issue
-
RestClientOptions.UserAgent missing from requests with useClientFactory: true可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
-
Expose HTTP response trailers on RestResponse可能已有人在做 @Benziza 于 13 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 68/100
-
RestClient configured with Newtonsoft.Json serializer still instantiates System.Text.Json可能已有人在做 @JiuYue0820 于 54 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 65/100
-
delete 940未关闭
难度 1/5 1 小时以内 新手友好度 35/100
-
js/calculator.js未关闭
难度 5/5 一周以上 新手友好度 10/100
查看 restsharp/RestSharp 的全部 Issue
相似的 Issue
-
area:jobads-cv BE mvp P2
难度 2/5 1-3 小时 新手友好度 62/100
klasolsson81/jobbliggaren#2099 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
0 - Backlog Bug
难度 2/5 1-3 小时 新手友好度 62/100
BrighterCommand/Brighter#4581 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 92/100
Esri/calcite-dotnet-toolkit#30 · 1 个 reaction ·
-
kind:docs simplification size:S status:todo
难度 2/5 1-3 小时 新手友好度 82/100
elsa-workflows/elsa-foundation#2604 ·
维护者通常 1 天内回复