The talk is devoted to the topic of performance optimization, but not really performance optimization, but the sins of performance optimization (in VictoriaMetrics).
Video
I'll tell you what it is later. First, Iβll tell you a little about myself.
- I am Alexander Valyalkin. My nickname is valyala.
- I am the author of Go libraries such as Fasthttp , Fastjson , Quicktemplate . These libraries are optimized for speed.
- .
- 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 .
Fastjson β encoding/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 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
.
Telegram chat: https://t.me/VictoriaMetrics_ru1