I wrote a load check program to emphasize an online service, which runs high-quality on Linux.
Nonetheless, on Home windows it runs out of ports in internet.Dial with this error:
Submit http://localhost:9090: dial tcp [::1]:9090: connectex: Just one utilization of every socket handle (protocol/community handle/port) is generally permitted.
I’ve tried altering the registry to extend the accessible port depend and decreasing the WAIT_TIME as described on this submit: Success Middle
Does anybody know if there’s a technique to re-use ports in order that Home windows doesn’t run out of ports (or another technique to obtain this load check)?
My code is under:
bundle fundamental
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"internet/http"
"os"
"strconv"
"time"
)
kind args struct {
url string
physique []byte
threads int
}
func fundamental() {
// 06-hammer url physique threads
if len(os.Args) != 4 {
showUsage()
return
}
var arg args
arg.url = os.Args[1]
physique := os.Args[2]
threads, err := strconv.Atoi(os.Args[3])
if err != nil || len(arg.url) < 1 || len(physique) < 1 {
showUsage()
return
}
arg.threads = threads
arg.physique, err = os.ReadFile(physique)
if err != nil {
fmt.Printf("error studying '%v': %v n", physique, err)
return
}
name(arg)
}
func showUsage() {
fmt.Println("Utilization:")
fmt.Println("06-hammer url physique threads")
fmt.Println("Instance:")
fmt.Println(`06-hammer http://localhost:9090 "./physique.json" 10`)
}
func name(arg args) {
begin := time.Now()
var succ int
var fail int
var try int
for {
c := parallel(arg)
try++
for i := 0; i < arg.threads; i++ {
outcome := <-c
if outcome {
succ++
} else {
fail++
}
}
if time.Since(begin) >= time.Period(time.Second*5) {
log.Printf("success: %v fail: %v elapsed: %v, avg: %v n", succ, fail, time.Since(begin), time.Period(int64(time.Since(begin))/int64(try)))
begin = time.Now()
succ = 0
fail = 0
try = 0
}
}
}
func parallel(arg args) chan bool {
out := make(chan bool)
for i := 0; i < arg.threads; i++ {
go caller(arg, out)
}
return out
}
func caller(arg args, c chan bool) {
var defaultTransport http.RoundTripper = &http.Transport{Proxy: nil, DisableKeepAlives: true}
consumer := &http.Shopper{Transport: defaultTransport}
r, err := consumer.Submit(arg.url, "software/json", bytes.NewReader(arg.physique))
if err != nil {
c <- false
return
}
defer r.Physique.Shut()
_, err = ioutil.ReadAll(r.Physique)
if err != nil {
c <- false
return
}
c <- true
}
This GitHub problem appears to reply your query:
The reply appears to be to set a MaxUserPort registry key to 65535 and a TcpTimedWaitDelay key to 30: Settings that may be Modified to Enhance Community Efficiency – BizTalk Server | Microsoft Docs
Hello Sean,
Thanks for replying!
I’ve already tried these registry settings as talked about within the unique query (to no avail).
Do you suppose it is smart to pool the connections by some means for the web.Dial perform?
I’ve an concept: It may very well be since you’re creating new *http.Shopper
s ever time caller
is known as. *http.Shopper
s cache their connections in order that new requests don’t at all times require opening new connections.
Relying on what you’re stress-testing, you both wish to:
-
Create the
*http.Shopper
s forward of time and re-use them (this may largely stress the API endpoint and never stress the remainder of the community stack as a lot) -
Name
(*http.Shopper).CloseIdleConnections
earlier than getting back fromcaller
(this may embrace the efficiency of opening and shutting connections in your stress check which can or will not be what you need).
This subject was robotically closed 90 days after the final reply. New replies are not allowed.