tcnksm / go-httpstat Goto Github PK
View Code? Open in Web Editor NEWTracing golang HTTP request latency
License: MIT License
Tracing golang HTTP request latency
License: MIT License
This is similar to #2 and results in the same (9223372036854
).
I'm trying to test the request time of a bunch of proxies by calling https://ipinfo.io/json with a proxy in the transport of the client.
When I'm running that code the request always has the exact same total time even though its proxies in other continents. Anything I'm missing? Code is basically the same as this one: https://github.com/tcnksm/go-httpstat/blob/master/_example/main.go except that I'm using a transport. I also added the output of the code from GoDoc which looks as expected
When I loop over your example code:
http://s.natalian.org/2016-10-05/main.go
I get odd results after the first:
http://s.natalian.org/2016-10-05/output.txt
What am I missing? I guess result needs to be re-initialised?
Not really an issue but may be feature. I am struggling to get the results converted to json because marshalling does skip the last lines of both the results (individual and total). Also, it is giving me in nano secs. Can you help me with that ? Thanks.
Just like as follows:
`package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"time"
"github.com/tcnksm/go-httpstat"
"sync"
//"runtime"
)
func worker(host string, wg *sync.WaitGroup) {
req, err := http.NewRequest("GET", host, nil)
if err != nil {
wg.Done()
return
}
var result httpstat.Result
ctx := httpstat.WithHTTPStat(req.Context(), &result)
req = req.WithContext(ctx)
client := http.DefaultClient
client.Timeout = 5 * time.Second
res, err := client.Do(req)
if err != nil {
wg.Done()
return
}
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
wg.Done()
return
}
res.Body.Close()
result.End(time.Now())
fmt.Println(result)
wg.Done()
}
func main() {
args := os.Args
if len(args) < 2 {
log.Fatalf("Usage: go run main.go URL")
}
//runtime.GOMAXPROCS(runtime.NumCPU())
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go worker(args[1], &wg)
}
wg.Wait()
}`
Hello,
Thanks again for the update in 1.8
I have a small issue since the update. I'm not sure it's linked to the update, but i don't understand.
i always have the same fix value for ContentTransfert:
with:
end := time.Now()
fmt.Println("result.ContentTransfer(end) ", result.ContentTransfer(end))
The result is always:
result.ContentTransfer(end) 2562047h47m16.854775807s
Thanks for your help,
Benoît
So after calling End
it would be great if I could access contentTransfer
duration on the result object. And particular reason why contentTransfer
and total
are private?
First off, thanks for writing this cool utility. Love how easy it is to add just a few lines and get nicely formatted statistics for a request.
Unfortunately I'm unable to use this in a production project that runs the test suite with the -race flag enabled. I'd like it if go-httpstat could avoid race conditions.
The golint package changed location recently, and this is causing the Travis buiild to fail.
I think I found a small bug in the code that does the calculations for the total amount of time. If you set all values to 0 (for example if there's an outtage) the result is 9223372036854
instead of 0
.
result := httpstat.Result{
DNSLookup: 0.0,
TCPConnection: 0.0,
TLSHandshake: 0.0,
ServerProcessing: 0.0,
NameLookup: 0.0,
Connect: 0.0,
Pretransfer: 0.0,
StartTransfer: 0.0,
}
result.End(time.Now())
If you print result
:
TLSHandshake: 0 ms, Total: 9223372036854 ms, StartTransfer: 0 ms, DNSLookup: 0 ms, TCPConnection: 0 ms, ServerProcessing: 0 ms, ContentTransfer: 9223372036854 ms, NameLookup: 0 ms, Connect: 0 ms, Pretransfer: 0 ms
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.