Skip to content

Instantly share code, notes, and snippets.

@agocs
Last active August 29, 2015 13:56
Show Gist options
  • Save agocs/9164543 to your computer and use it in GitHub Desktop.
Save agocs/9164543 to your computer and use it in GitHub Desktop.
A dumb http client that GETs a few different URLs.
package main
import "net/http"
import "fmt"
import "time"
type http_req struct {
req_time time.Duration
url string
status string
}
var http_times = make(chan http_req)
func main() {
start := time.Now()
go bother("http://example.com")
go bother("http://tumblr.com")
go bother("http://yahoo.com")
go bother("http://jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com")
go bother("http://penny-arcade.com")
go bother("http://google.com")
go bother("http://taco-mac.com")
go bother("http://apple.com")
go bother("http://python.org")
go bother("http://mitsubishi.com")
go bother("http://toyota.com")
go bother("http://ford.com")
go bother("http://chevrolet.com")
go bother("http://audi.com")
go bother("http://subaru.com")
go bother("http://bmw.com")
go bother("http://honda.com")
go bother("http://motorola.com")
go bother("http://cingular.com")
go bother("http://att.com")
go bother("http://ibm.com")
go bother("http://compaq.com")
go bother("http://dell.com")
go bother("http://cdw.com")
for i := 0; i < 24; i++ {
fmt.Println(<-http_times)
}
fmt.Println("I have returned.")
fmt.Println(time.Since(start))
}
func bother(who string) {
start := time.Now()
resp, err := http.Get(who)
if err != nil {
http_times <- http_req{time.Since(start), who, err.Error()}
} else {
http_times <- http_req{time.Since(start), who, resp.Status}
}
}
@agocs
Copy link
Author

agocs commented Feb 23, 2014

46.915823ms
1.47659371s
1.519179555s
3.491094925s
I have returned.
3.491187123s

@agocs
Copy link
Author

agocs commented Feb 23, 2014

cagocs:dumbclient christopheragocs$ go run dumbclient.go
119.83483ms
138.044343ms
288.122868ms
311.846372ms
547.900214ms
610.11075ms
639.072908ms
791.612689ms
829.899068ms
860.079436ms
882.204731ms
904.214409ms
946.928013ms
1.045613679s
1.060173901s
1.166321178s
1.309443154s
1.338787169s
1.465837791s
1.480272087s
1.667257189s
1.684083537s
2.038563262s
3.531915522s
I have returned.
3.532110566s

@agocs
Copy link
Author

agocs commented Feb 23, 2014

cagocs:dumbclient christopheragocs$ go run dumbclient.go
{9364420 http://jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com Get http://jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com: dial tcp: lookup jsdfnlsdnsdlngsldsfnglsdknlkn3443l43.com: no such host}
{719365213 http://taco-mac.com Get http://taco-mac.com/?3e3ea140: EOF}
{983039621 http://example.com 200 OK}
{1219575832 http://penny-arcade.com 200 OK}
{1449042678 http://python.org 200 OK}
{1807195478 http://honda.com 200 OK}
{1847580758 http://mitsubishi.com 403 Forbidden}
{1947187626 http://subaru.com 200 OK}
{2237452752 http://compaq.com 200 OK}
{2428606022 http://google.com 200 OK}
{2466545761 http://cdw.com 200 OK}
{2922516086 http://apple.com 200 OK}
{2945832716 http://ford.com 200 OK}
{3248721581 http://bmw.com 200 OK}
{3335337918 http://chevrolet.com 200 OK}
{3879777276 http://att.com 200 OK}
{4075555273 http://dell.com 200 OK}
{4834800209 http://motorola.com 200 OK}
{6207428818 http://audi.com 200 OK}
{6322143521 http://ibm.com 200 OK}
{6951210760 http://tumblr.com 200 OK}
{7240776729 http://yahoo.com 200 OK}
{8171975140 http://toyota.com 200 OK}
{8251384868 http://cingular.com 200 OK}
I have returned.
8.251663736s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment