V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
line
V2EX  ›  Go 编程语言

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

  •  
  •   line ·
    linexjlin · 2019-04-26 22:05:09 +08:00 · 3410 次点击
    这是一个创建于 1798 天前的主题,其中的信息可能已经有所发展或是发生改变。

    下面这段代码编译出来程序,运行在 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 条回复    2019-04-26 22:31:17 +08:00
    Mohanson
        1
    Mohanson  
       2019-04-26 22:25:56 +08:00 via Android   ❤️ 1
    试过直接用 curl 吗?我觉得有点不可思议… go 的 http 服务和客户端默认只保留 2 个长连接,但原则上是会自动扩容的
    line
        2
    line  
    OP
       2019-04-26 22:31:17 +08:00
    @Mohanson 我用 wget 手工模拟也是
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2556 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:57 · PVG 23:57 · LAX 08:57 · JFK 11:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.