-
-
Notifications
You must be signed in to change notification settings - Fork 751
why resty very slow #205
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
using : https://github.com/andelf/go-curl time ./main
real 0m1.413s
user 0m0.034s
sys 0m0.021s |
@codenoid Thanks for trying Resty! Happy new year 2019! I thought I will not touch my laptop today, but I checked my email and jumped on it 🎉 I can assure you Resty performance is damn good (I'm proud of it 😄). As always testing performance involves many factors. Its applies to testing http client too. Above stated scenario involves (few comes to my mind)-
I have updated your code snippet with few additional info. Resty always captures timing of -
Code snippet package main
import (
"fmt"
"time"
"gopkg.in/resty.v1"
)
func main() {
startTime := time.Now()
resp, _ := resty.R().Get("http://httpbin.org/get")
endTime := time.Since(startTime)
fmt.Println("Total Time", endTime)
fmt.Println("Request Fire Time", resp.Request.Time)
fmt.Println("Response Received Time (body not read yet)", resp.ReceivedAt())
fmt.Println("Diff request fire & receive", resp.Time())
fmt.Println(resp)
} Okay, let's proceed to execute. First run : (clear local dns cache before each run)Resty
curl
Second run: (clear local dns cache once and order is Resty and then curl)Resty
curl
Third run: (clear local dns cache once and order is curl and then Resty)curl
Resty
I'm not sure, how much above results gonna help you. I would suggest test your use case (with some realistic approach like above follow some consistent steps). If you come across bottleneck in Resty, please let me know I'm glad to work on it. Help me with some concrete inputs and data from you. Again, thanks for trying Resty 😄. |
after following this script to flush DNS in my Ubuntu + with updated code :
|
@codenoid It seems we need to further investigation. We cannot use https://github.com/andelf/go-curl since it's a binding for curl cmd. Let's try Go default client at your end. Default Go client snippet Resembles same behavior as Resty package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
func main() {
startTime := time.Now()
resp, err := http.Get("http://httpbin.org/get")
if err != nil {
log.Fatal(err)
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
endTime := time.Since(startTime)
fmt.Println("Total Time", endTime)
fmt.Println(string(b))
} FYI, I have tried Resty and above go default client code snippets on - My machine:
My DO VPS:
On both machine Resty and Default Go Client performs very good. Could you try above default client code snippet at your end then provide the outcome also your env info? |
I was curious, so I made a
@jeevatkm, what do you think about adding this kind of tracer to Resty? |
@moorereason Thank you. Nice suggestion👍 Just added to v2 action list #167 . Good to have on-demand tracer option in the Resty. @codenoid Could you please also run @moorereason's code snippet ( |
result :
|
@codenoid Thanks for trying with @moorereason code snippet. It seems on your machine, major time is occupied by As always, feel free to ping me when needed. |
but what about with curl 😕
should i close this issue for a while ? |
@codenoid I understand what you're trying to convey. BTW what is your Go version?? Could you try with latest Go 1.11.4 version. We can keep this issue open for a while 😄. I have looked around found following issues on Go repo: I have created a Go HTTP client with tracer based on @moorereason snippet. package main
import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptrace"
"time"
)
type HTTPTracer struct {
GetConn time.Time
GotConn time.Time
GotFirstResponseByte time.Time
DNSStart time.Time
DNSDone time.Time
ConnectStart time.Time
ConnectDone time.Time
TLSHandshakeStart time.Time
TLSHandshakeDone time.Time
}
func (t *HTTPTracer) Context() context.Context {
return httptrace.WithClientTrace(
context.Background(),
&httptrace.ClientTrace{
GetConn: func(_ string) { t.GetConn = time.Now() },
DNSStart: func(_ httptrace.DNSStartInfo) { t.DNSStart = time.Now() },
DNSDone: func(_ httptrace.DNSDoneInfo) { t.DNSDone = time.Now() },
ConnectStart: func(_, _ string) {
if t.DNSDone.IsZero() {
t.DNSDone = time.Now()
}
},
GotConn: func(_ httptrace.GotConnInfo) { t.GotConn = time.Now() },
GotFirstResponseByte: func() { t.GotFirstResponseByte = time.Now() },
TLSHandshakeStart: func() { t.TLSHandshakeStart = time.Now() },
TLSHandshakeDone: func(_ tls.ConnectionState, _ error) { t.TLSHandshakeDone = time.Now() },
},
)
}
func main() {
tr := &HTTPTracer{}
req, _ := http.NewRequest("GET", "http://httpbin.org/get", nil)
req = req.WithContext(tr.Context())
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
endTime := time.Now()
if tr.DNSStart.IsZero() {
tr.DNSStart = tr.GetConn
tr.DNSDone = tr.GetConn
}
fmt.Println(string(b))
fmt.Println("DNS Lookup", tr.DNSDone.Sub(tr.DNSStart))
fmt.Println("TCP Connection", tr.GotConn.Sub(tr.DNSDone))
fmt.Println("Server Processing", tr.GotFirstResponseByte.Sub(tr.GotConn))
fmt.Println("TLS Handshake", tr.TLSHandshakeDone.Sub(tr.TLSHandshakeStart))
fmt.Println("Content Transfer", endTime.Sub(tr.GotFirstResponseByte))
fmt.Println("Total Time", endTime.Sub(tr.GetConn))
} Try this one and with this data reach out to Go community on Google Group or Slack channel. If anyone have clue around this. |
GO Version : $ go version
go version go1.11 linux/amd64
$ go run main.go
{
"args": {},
"headers": {
"Accept-Encoding": "gzip",
"Connection": "close",
"Host": "httpbin.org",
"User-Agent": "Go-http-client/1.1"
},
"origin": "xxx.xxx.xxx.xxx",
"url": "http://httpbin.org/get"
}
DNS Lookup 10.305910554s
TCP Connection 242.929337ms
Server Processing 248.50648ms
TLS Handshake 0s
Content Transfer 308.082µs
Total Time 10.797677572s USING GO 1.11.4 🚀
|
thank you ! 🚀 ✨ |
@codenoid I'm glad to hear that you have to sorted the issue 😄 |
I have the same problem,the output with http HTTPTracer。 DNS Lookup 1.546709ms but using curl command is very fast time_namelookup: 0.109017s |
@wlstony I think it is related to your Go environment, machine, or connection. See these two lines: it took a lot of time -
You could also try the Go HTTP client directly; if the issue is the same as mentioned above, you will get the same result. |
Resty vs Curl
Result
Resty + fmt :
time ./main real 0m11.247s user 0m0.045s sys 0m0.027s
curl :
Code
The text was updated successfully, but these errors were encountered: