Behavior of HttpClient Class(C#)

★★★ お知らせ ★★★

◆ 6月のPS Liveは決済サービスStripeのデモ!◆
決済サービスのStripeでサブスクリプションの支払い機能を作ってみた
Stripeの機能の一部を切り出して、簡単なサブスクリプションを作るとどうなるのかを、デモをまじえてご紹介します。
⇒ 詳細はこちらから

◆【セミナー開催】 可視化ツールGrafana~初めてのダッシュボード作成◆
デモンストレーション付き!
本セミナーでは、売上データを用いて、4種類のパネル作成方法をお見せします。
⇒ お申込みはこちらから

◆ エンジニア業務環境アンケート結果 ◆
エンジニアが自分の働き方にどういったことで満足していて、不満を感じているのか、働きたい会社像として何を求めているのか、業務環境調査を実施しました。ぜひご覧ください。
⇒ アンケート結果はこちらから

The official document provided by Microsoft describes that how HttpClient class works when connecting to a specific URL.

https://docs.microsoft.com/en-us/dotnet/api/system.net.https.httpsclient

As described in the link above,it is neccessary to make HttpClass instances static and readonly,instead of creating HttpClass instance everytime connecting.I did some investigation.

I tried to execute the following code which invoke 10 threads and each thread connect to the specific URL.As shown below,this code creates HttpClass instance evrytime connecting.

I tried to get this traffic captured in wireshark and filter captured packets by TCP Flag which is on and HTTP Status Code which is 200.I can see that TCP connection is established everytime connecting.

Screen Shot 2018-12-27 at 8.31.37

 

Next,I tried to execute the following code which makes HttpClass instance static and readonly as the official documents provided by Microsoft describes.

Take a look at the following result.Only 2 TCP connections are established,but there are 10 HTTP responses whose source tcp port are the ones above-mentioned 2 TCP connections established(54672 and 54673).You can see the TCP connections reused.

Screen Shot 2018-12-27 at 8.29.37

アバター画像
About 武井 宜行 251 Articles
Microsoft MVP for Azure🌟「最新の技術を楽しくわかりやすく」をモットーにブログtech-lab.sios.jp)で情報を発信🎤得意分野はAzureによるクラウドネイティブな開発(Javaなど)💻「世界一わかりみの深いクラウドネイティブ on Azure」の動画を配信中📹 https://t.co/OMaJYb3pRN
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

0人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる