The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
line

运行在 Windows 下的 Go 写的文件服务器只有两并发?

  •  
  •   line ·
    linexjlin · Apr 26, 2019 · 4266 views
    This topic created in 2603 days ago, the information mentioned may be changed or developed.

    下面这段代码编译出来程序,运行在 Windows 下最多只有两并发(用 IDM 之类的工具下载文件,最多只能两线程,第三个会 hang 住)。 同样的代码运行在 Linux 下就没有这个问题。

    package main
    
    import (
            "flag"
            "log"
            "net/http"
    )
    
    func main() {
            port := flag.String("p", "8022", "port to serve on")
            directory := flag.String("d", ".", "the directory of static file to host")
            flag.Parse()
    
            http.Handle("/", http.FileServer( http.Dir(*directory)))
    
            log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
            log.Fatal( http.ListenAndServe(":"+*port, nil))
    }
    
    2 replies    2019-04-26 22:31:17 +08:00
    Mohanson
        1
    Mohanson  
       Apr 26, 2019 via Android   ❤️ 1
    试过直接用 curl 吗?我觉得有点不可思议… go 的 http 服务和客户端默认只保留 2 个长连接,但原则上是会自动扩容的
    line
        2
    line  
    OP
       Apr 26, 2019
    @Mohanson 我用 wget 手工模拟也是
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1064 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 18:45 · PVG 02:45 · LAX 11:45 · JFK 14:45
    ♥ Do have faith in what you're doing.