-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Warmup connections #1982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What exactly do you mean with warmup? |
Let's say we have an SLA of 250ms, which will be our timeout for an HTTP request. For example, we know that we establish a TCP connection in ~200ms and the HTTP request/response roundtrip takes ~100ms, therefore, we will timeout always because 200ms+100ms > 250ms. We want to have an interface to warmup or, in other words, create a number of TCP connections in advance before the actual requests or even in parallel, and save them to the connection pool to overcome the timeout problem. Currently, there's no such interface. We have an |
func main() {
hc := fasthttp.HostClient{
Addr: "google.com:80",
}
// Use a closure so we can defer ReleaseConn. The return value of
// AcquireConn is not exported so we can't easily store it in a slice
// to release it later for example.
func() {
for range 10 {
c, err := hc.AcquireConn(0, false)
if err != nil {
panic(err)
}
defer hc.ReleaseConn(c)
}
}()
// At this point we will have 10 connections open ready for use.
fmt.Println(hc.ConnsCount())
} |
Yes, but we may need to do a warmup dynamically while we are already using |
Does that matter? As long as you aquire as many conns as you need it should be fine. And it's a quick process so the conn can be used again right away. |
Is there a proper way to warm up a connection using
HostClient
? There's anAcquireConn
method but it may return a ready connection from pool whereas I need to establish and save a new connection to the connection pool. Also, I need to warm up connections in the middle of usingHostClient
soAcquireConn
doesn't sound like a proper solution due to above reason.The text was updated successfully, but these errors were encountered: