RestClient.Execute() is extremely slow compared to RestClient.ExecuteAsync().Result
まだ誰も着手していません。
評価
- 難易度
- 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 ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
restsharp/RestSharp のほかの issue
-
RestClientOptions.UserAgent missing from requests with useClientFactory: true対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
Expose HTTP response trailers on RestResponse対応中かも @Benziza が 14 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
-
RestClient configured with Newtonsoft.Json serializer still instantiates System.Text.Json対応中かも @JiuYue0820 が 55 日前に担当しました。 オープンbug
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
-
delete 940オープン
難易度 1/5 1時間未満 初心者へのやさしさ 35/100
-
js/calculator.jsオープン
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
restsharp/RestSharp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
rjmurillo/moq.analyzers#1468 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
[誤判定] `define` が `デフィね`・`デフィ値` になる対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン再現済み 要トリアージ 誤判定
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
yksr-melt/Meltype#421 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
Facepunch/sbox-public#12063 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信