1

I am trying to create a fairly simple http file server in Go. Ideally, it should be able to support multiple concurrent file downloads from 2 to 20 clients simultaneously.

I have tried several different approaches including the using the "net/http" and "gorilla" libraries with the same unsuccessful results: the first two clients connect and begin downloading the file normally. Any additional connections fail until one of the first two completes.

Is there a maximum number of concurrent connections / downloads of the same file and can this be increased?

  • Operating system: Windows 10 Enterprise - max 2 concurrent
  • Operating system: Ubuntu 22.04 - unknown max, but at least 15
  • Operating system: Raspbian v11 - unknown max, but at least 15

Very simplified code example below:

package main

import (
    "log"
    "net/http"
)

func main() {
    log.Printf("\nListening... [:80]")

    mux := http.NewServeMux()
    mux.Handle("/", http.FileServer(http.Dir(".")))

    if err := http.ListenAndServe(":80", mux); err != nil {
        log.Fatalf("Could not start server: \n %v", err)
    }

}
5
  • 2
    The maximum is system dependent, as is how you would change that. 2-20 is trivial, so you would ned to show a minimal reproducible example of the problem for anyone to offer a specific answer. Commented Jul 18, 2022 at 13:17
  • Be sure any concurrent clients are properly closing the body response of any web calls. Without this the server will not be able to do connection reuse & resources will eventually became exhausted as new unclosed connections pile up. Commented Jul 18, 2022 at 15:03
  • @JimB added detail that original test machine is Win10 Enterprise. Confirmed Unbuntu 22.04 supports at least 6 concurrent connections. On Win10 can this limitation be increased? Commented Jul 18, 2022 at 18:39
  • @Peter: you need to provide more info or a working example. When I say that you can increase the maximum, I mean starting in the thousands. If you cannot handle 2-20 concurrent connections then there is something else going on. Commented Jul 18, 2022 at 18:47
  • @JimB Thank you for assisting - the code I included is a working example I think? The same code on Win10 does not allow more than 2 concurrent connections while on Ubuntu 22.04 I was able to have 15 concurrent downloads. As you suggested, it appears to be OS specific. Can this be modified for Win10? Commented Jul 18, 2022 at 18:53

1 Answer 1

2

I ran into the same issue and investigated it.

Go uses a Windows API function called TransmitFile to transmit file data over connected sockets. Workstation and client versions of Windows limit the number of concurrent TransmitFile operations allowed on the system to a maximum of two. This is what causes the issue.

I reported this and submitted a change that makes Go avoid TransmitFile in such cases. The change has been merged and should be included in the next release of Go.

See:

https://github.com/golang/go/issues/73746

https://go-review.googlesource.com/c/go/+/673855

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.