Wednesday, November 30, 2022
HomeGolangLoad check program runs out of ports in Home windows - Getting...

Load check program runs out of ports in Home windows – Getting Assist

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 (

kind args struct {
	url     string
	physique    []byte
	threads int

func fundamental() {
	// 06-hammer url physique threads
	if len(os.Args) != 4 {

	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 {
	arg.threads = threads
	arg.physique, err = os.ReadFile(physique)
	if err != nil {
		fmt.Printf("error studying '%v': %v n", physique, err)

func showUsage() {
	fmt.Println("06-hammer url physique threads")
	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)

		for i := 0; i < arg.threads; i++ {
			outcome := <-c
			if outcome {
			} else {

		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
	defer r.Physique.Shut()

	_, err = ioutil.ReadAll(r.Physique)
	if err != nil {
		c <- false

	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.Shoppers ever time caller is known as. *http.Shoppers 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:

  1. Create the *http.Shoppers 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)

  2. Name (*http.Shopper).CloseIdleConnections earlier than getting back from caller (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.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments