パフォーマンス最適化の罪。Alexander Valyalkin、Victoria Metrics



トークは、パフォーマンスの最適化のトピックに焦点を当てていますが、実際のパフォーマンスの最適化ではなく、パフォーマンスの最適化の罪です(VictoriaMetricsで)。



ビデオ





それは何ですか-後でお話します。まず、自分自身について少しお話します。





  • 私はアレクサンダー・バリャルキンです。私のニックネームはバリャラです。
  • 私は、FasthttpFastjsonQuicktemplateなどのGoライブラリの作成者です。これらのライブラリは、速度が最適化されています。
  • .
  • timeseries VictoriaMetrics.




? , :



  • .
  • hardware , , .
  • – benchmark games. , benchmarks. production.




, . . , .



Fasthttp, fastjson, VictoriaMetrics. Go . Go. .





Fasthttp. Fasthttp – net/http, , .





Fasthttp , :



  • .
  • HTTP headers.
  • slices maps key->value .
  • requestCtx.
  • DNS .




c . HTTP Go. .



. http . , . , . , . , . . keep-alive, .



? , , / , . . .





, . , HTTP pipelining .



HTTP pipelining – HTTP , .



. . bufio.NewReader bufio.NewWriter. . : , , Write .



, . , , .



pipelining connection. ? – - , . , , , .





? , , . 4 . . . , bufio.Reader, reader 4- .



4 , . , .



. 4 , . , , «flush». . , . .





https://en.wikipedia.org/wiki/HTTP_pipelining#Implementation_status



https://github.com/TechEmpower/FrameworkBenchmarks/issues/4410



.



, HTTP pipelining head of line blocking. - , , HTTP connection , , . , .



. HTTP pipelining . , , HTTP pipelining, . ? HTTP, 2000- , HTTP pipelining, HTTP pipelining. , HTTP pipelining. HTTP 2.0 . , HTTP pipelineing, HTTP 2.0.



HTTP pipelining – , , Techempower benchmarks . Techempower benchmark – , HTTP . , plaintext. 16 pipelining requests . HTTP pipelining fasthttp 2 .



. . , , , .





– HTTP headers.



Fasthttp HTTP headers . HTTP headers. . headers byte slice . byte slice HTTP headers.





Fasthttp, HTTP header . : «Hello, world!» http http headers.





, http headers. , header «X-Forwarded-For», Fasthttp HTTP header.





? , HTTP , HTTP headers .





– , http . , , . .





slices maps. Fasthttp slices key->value go’ map' , , . . , query args, cookies.





, . key->value byte slices.





slice map.



? , slice map – byte slice. kvs – byte slice . capacity , , , . . . slice, . . -. — [:0], , , kv.value, - .



slice map, kv.value byte slice slice map. , , .





slice map. slice map’ . , . .





? , slice maps, , query args cookies, — . slice maps , map Go.



, , slice maps maps. . . slice maps .



, — , . . . query args , slice map , map, map.





. query args , , , slice map – O(N) , . . , slice. , slice map, .



— , slice map . , slice map - , , , slice map , .



— , , slice map, slice map. , slice map . .





RequestCtx . RequestCtx – , http.ResponseWriter http.Request. , RequestHandler. HTTP .



. . RequestCtx. . ctx.Request. RequestHandler RequestCtx response connection. . . . RequestHandler RequestCtx , , , RequestHandler.





? , RequestCtx. , , . .





, , . API . , - RequestCtx RequestHandler - , , . RequestHandler. , Fasthttp, . . RequestCtx , , , .



, — . RequestCtx - request response body, - . RequestCtx , . .





– DNS. Fasthttp . resolve DNS . Fasthttp DNS , . . resolving. Fasthttp mapping name ip .



, . resolveHost. dnsCache map’a. . , , . , locks. , . , .





? DNS resolving.





– , HTTP , DNS . – Kubernetes, pods, IP-. , , Fasthttp , pod’ . , .





Fasthttp . Fastjson .



Fastjsonencoding/json. , . , .





"" fastjson:



  • .



  • .



  • integers floats.







. Fastjson Parser, JSON. , , .



. Parser.Parse. value. value . . . value Parser. foo. b. b .



JSON. v b, , v p, . . . vv, , .





? , JSON.





– , API . , , , JSON’, .



– , , . . . JSON , , , , 1 , JSON, , 2 , . . . 2 .





– unescaping . Fastjson . escape . escape , . . escape , , .





, , escape , . strings.IndexByte — go’ . .





– , escape .



– , , escape , — , , , . .





– floats integer Fastjson.





, , strconv.





? : « strconv ?». , . . edge cases. . . , strconv . , , , strconv.



– , 0, .



– , - , .





VictoriaMetrics .





. VictoriaMetrics Prometheus remote write API . protobufs.





protobuf , Prometheus. , , . .





. protobuf. timeseries, labels samples. label name value. Sample, , timestamp.





. labels name string. byte slice. , , , name. byte slice data string. , . . string . , , . .





. slice labels, . . slice labels. . label , label , label. capacity , , .





, . , , protobuf.





, . , string byte slice, byte slice , name. byte slice, protobuf, , , name , .





. – .





sync.Pool.





. strconv.FormatInt Go . Int, nSmalls, 99 100. base ( , ) 10. small, .





? , , 100, .





, , , . . . , , , .





sync.Pool — .

— . , sync.Pool byte slice, byte slice'.





— CPUs. (pipeline). pipeline , , , . , . . pipeline .



. , — . , , Meltdown Spectre, - .





. . , — ? API. . ..





Fasthttp , . . . benchmarks. ? - 10 %, . . 10 % 200 %?



. . , 10 %, . Fasthttp , TechEmpower benchmarks. c Fasthttp, net/http.



電報チャット:https : //t.me/VictoriaMetrics_ru1




All Articles