mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

HTTP2 #20

Open mtchuyen opened 2 years ago

mtchuyen commented 2 years ago

http://www.inanzzz.com/index.php/post/9ats/http2-and-tls-client-and-server-example-with-golang

The performance benefits of HTTP/2 come from simultaneous/parallel (pipelining) and batch requests. For example based on my tests, HTTP/2 was able to handle 500,000 requests (30sec~) but HTTP/1 barely managed 100 requests with many "broken pipe", "connection reset by peer" errors. The tests issued requests as in goroutines.

cannot read input protocol buffer message, Error: read tcp internalIP:8080->outerIP:17194: read: connection reset by peer, in protocol: HTTP/1.1 from:publicIP host:logging.domain.vn, X-Client: , X-Client-Rip: ripIP

why is golang http server failing with broken pipe when response exceeds 8kb?

https://www.appsloveworld.com/go/5/why-is-golang-http-server-failing-with-quotbroken-pipequot-when-response-exce

mtchuyen commented 2 years ago

https://groups.google.com/g/golang-nuts/c/E2-5kOb2iHc

https://github.com/akhld/simple-go-http2-server/blob/master/main.go

https://groups.google.com/g/golang-nuts/c/K3xNCmjEX2w

https://github.com/nghttp2/nghttp2

https://github.com/golang/go/issues/15425

https://github.com/nspeed-app/http2issue

mtchuyen commented 2 years ago

HTTP2 là gì?

https://200lab.io/blog/http2-la-gi/

Tổng quan HTTP2

https://viblo.asia/p/tong-quan-http2-aWj53OEQ56m

Mục tiêu chính của HTTP/2 là reduce latency (giảm độ trễ) bằng cách:

Source: https://viblo.asia/p/toi-uu-tai-trang-voi-http2-server-push-va-nodejs-63vKjaqk52R

A Comprehensive Guide To HTTP/2 Server Push

https://www.smashingmagazine.com/2017/04/guide-http2-server-push/

HTTP/2 Push là gì, dùng preload hay HTTP/2 Push thì tốt hơn

https://wptangtoc.com/http-2-push

HTTP/2 Push cho phép các lập trình viên nhà quản trị trang web xác định nội dung file cụ thể nào đó sẽ được đẩy gửi sớm nhất đến trình duyệt của người dùng cùng với tài liệu HTML (sớm nhất có thể).

mtchuyen commented 1 year ago

Xử lý vấn đề preprocess-Handler

vấn đề preprocess-Handler: tiền xử lý handler, nghĩa là các hoạt động trước khi thực hiện xử lý logic handle đó.

https://stackoverflow.com/questions/31770872/router-in-go-run-a-function-before-each-http-request

https://rickyanto.com/how-to-write-simple-middleware-using-go-nethttp-standard-library/

https://themue.dev/blog/2019/03/23/dont-be-afraid-of-multiplexing/

mtchuyen commented 1 year ago

Make resilient Go net/http servers using timeouts, deadlines and context cancellation

https://ieftimov.com/posts/make-resilient-golang-net-http-servers-using-timeouts-deadlines-context-cancellation/

mtchuyen commented 1 year ago

Client post http2

Client command by curl

curl -I --http2-prior-knowledge https://beta.domain.com/infor.html

Show body response with http2 protocol:

curl --http2-prior-knowledge -s -w "%{http_code}\n" -o /tmp/tmpFifo 127.0.0.1:1234/infor.html

Client send request by code

reqbody := bytes.NewReader(out)
resp, err := client.Post("https://beta.domain.com/app_view", "application/octet-stream", reqbody)

HAProxy setup

https://unix.stackexchange.com/questions/631001/why-is-haproxy-forwarding-http2-requests-as-http-1-1

https://www.haproxy.com/fr/blog/haproxy-2-0-and-beyond/#end-to-end-http-2

https://andreaskaris.github.io/blog/networking/haproxy-and-h2c/

https://www.haproxy.com/documentation/hapee/latest/load-balancing/protocols/http-2/

mtchuyen commented 1 year ago

Echo framwork for HTTP2

Handling HTTP request in Go Echo framework (1): https://medium.com/@ykyuen/handling-http-request-in-go-echo-framework-1-2b564663024

Build a Golang RESTful Stock API With the Echo Framework: https://betterprogramming.pub/intro-77f65f73f6d3

https://rakyll.org/http2push/

https://github.com/devsunset/go-work/tree/master/src

https://github.com/kwangchin/go-echo-vue

mtchuyen commented 1 year ago

Caddy is an extensible server platform that uses TLS by default.

https://github.com/caddyserver/caddy

mtchuyen commented 10 months ago

redis: connection reset by peer

netstat -antup | grep :6379 | grep "establish" | wc -l

🔌 Handle 'connection reset by peer' error in Go:

https://gosamples.dev/connection-reset-by-peer/