Upgrade to Pro — share decks privately, control downloads, hide ads and more …

fiberについて

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.
Avatar for kuro kuro
July 17, 2022

 fiberについて

Avatar for kuro

kuro

July 17, 2022
Tweet

More Decks by kuro

Other Decks in Programming

Transcript

  1. 実際に手元でも試してみる。。。 gin 1,経過: 86115ns 2,経過: 56648ns 3,経過: 65380ns 4,経過: 118521ns

    5,経過: 62619ns 6,経過: 68169ns 7,経過: 57073ns 8,経過: 92922ns 9,経過: 79548ns 10,経過: 57686ns 平均74468.1ns
  2. なぜfasthttpは速いのか? https://github.com/valyala/fasthttp • Why creating yet another http package instead

    of optimizing net/http? Because net/http API limits many optimization opportunities. For example: ◦ net/http Request object lifetime isn't limited by request handler execution time. So the server must create a new request object per each request instead of reusing existing objects like fasthttp does. ◦ net/http headers are stored in a map[string][]string . So the server must parse all the headers, convert them from []byte to string and put them into the map before calling user-provided request handler. This all requires unnecessary memory allocations avoided by fasthttp. ◦ net/http client API requires creating a new response object per each request. なぜ、net/httpを最適化する代わりに、さらに別のhttpパッケージを作成するのですか? net/http APIは、多くの最適化の機会を制限しているからです。 net/http ヘッダは map[string][]string に格納されます。ですから、サーバはすべてのヘッダを解析し、 []byte から文字列に変換 し、ユーザが提供するリクエストハンドラを呼ぶ前にそれらを mapに入れなければなりません。これには、 fasthttpが回避してい る、不要なアロケーションが必要になります。