Skip to content

Commit

Permalink
DNS cache speeds up everything
Browse files Browse the repository at this point in the history
  • Loading branch information
chillum committed Sep 1, 2018
1 parent 92d6836 commit 9de0464
Show file tree
Hide file tree
Showing 8 changed files with 428 additions and 4 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
httpstress: https://github.com/chillum/httpstress

Copyright 2014-2016 Vasily Korytov
Copyright 2014-2018 Vasily Korytov

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this software except in compliance with the License.
Expand Down
25 changes: 23 additions & 2 deletions lib/httpstress.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ A CLI utility is avaliable at github.com/chillum/httpstress
package httpstress

import (
"context"
"errors"
"net"
"net/http"
"strings"

"github.com/rs/dnscache"
)

// Version is the library version
const Version = "2.1.1"
const Version = "2.2"

/*
Test launches {conn} goroutines to fetch HTTP/HTTPS locations in {urls} list
Expand Down Expand Up @@ -63,7 +67,24 @@ func Test(conn int, max int, urls []string) (results map[string]int, err error)
results = make(map[string]int)
finished := make(chan string)
total := len(urls) - 1
trans := &http.Transport{MaxIdleConnsPerHost: conn} // Use persistent connections.
r := &dnscache.Resolver{}
trans := &http.Transport{
MaxIdleConnsPerHost: conn, // Use persistent connections.
DialContext: func(ctx context.Context, network string, addr string) (conn net.Conn, err error) {
separator := strings.LastIndex(addr, ":")
ips, err := r.LookupHost(ctx, addr[:separator])
if err != nil {
return nil, err
}
for _, ip := range ips {
conn, err = net.Dial(network, ip+addr[separator:])
if err == nil {
break
}
}
return
},
}
client := &http.Client{Transport: trans}
client.CheckRedirect = redirect
n := 0
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
)

// Version is the application version
const Version = "6.3.1"
const Version = "6.4"

type results struct {
Errors interface{} `json:"errors"`
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/rs/dnscache/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions vendor/github.com/rs/dnscache/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

190 changes: 190 additions & 0 deletions vendor/github.com/rs/dnscache/dnscache.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9de0464

Please sign in to comment.