Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缓冲对Bluemix应用程序的http请求_Http_Ibm Cloud_Buffering - Fatal编程技术网

缓冲对Bluemix应用程序的http请求

缓冲对Bluemix应用程序的http请求,http,ibm-cloud,buffering,Http,Ibm Cloud,Buffering,我有一个写在Golang上的Bluemix应用程序。我向它发送了一个大的分块HTTP请求,我看到我的应用程序收到一个通知,只有当请求完全到达目的地时,它才收到这个请求,而不是在头出现后启动(在开始时不等待主体) 同样的代码在普通服务器上运行良好,没有任何延迟,问题似乎只有在Bluemix上运行时才会出现。我做了几个实验,比如听tcp而不是http(但仍然发送http请求),第一次注意到只有当请求完全到达时才有一些网络。我还尝试以非常慢的速度传输数据,100毫秒1字节,并发送小请求,结果是一样的

我有一个写在Golang上的Bluemix应用程序。我向它发送了一个大的分块HTTP请求,我看到我的应用程序收到一个通知,只有当请求完全到达目的地时,它才收到这个请求,而不是在头出现后启动(在开始时不等待主体)

同样的代码在普通服务器上运行良好,没有任何延迟,问题似乎只有在Bluemix上运行时才会出现。我做了几个实验,比如听tcp而不是http(但仍然发送http请求),第一次注意到只有当请求完全到达时才有一些网络。我还尝试以非常慢的速度传输数据,100毫秒1字节,并发送小请求,结果是一样的

我假设在将请求重定向到应用程序拥有的动态端口之前,或者在其他地方,存在一些缓冲。我们将非常感谢您对为什么会发生这种情况以及如何避免这种情况的任何帮助。多谢各位

UPD:Go中侦听TCP的服务器代码:

func main() {
    var port string
    if port = os.Getenv("PORT"); len(port) == 0 { port = DEFAULT_PORT }
    l, err := net.Listen("tcp", ":"+port)
    if err != nil {
        fmt.Println("Error listening:", err.Error())
        os.Exit(1)
    }
    // Close the listener when the application closes.
    defer l.Close()
    for {
        // Listen for an incoming connection.
        conn, err := l.Accept()
        if err != nil {
            fmt.Println("Error accepting: ", err.Error())
            os.Exit(1)
        }
        // Handle connections in a new goroutine.
        go handleTCPRequest(conn)
    }
}

func handleTCPRequest(conn net.Conn) {
    fmt.Println("Got something!!!", conn)
    // Make a buffer to hold incoming data.
    buf := make([]byte, 1024)
    // Read the incoming connection into the buffer.
    reqLen, err := conn.Read(buf)
    if err != nil {
        fmt.Println("Error reading:", err.Error(), conn)
    } else {
        fmt.Println("Read: ", reqLen, buf, conn)
    }
    // Close the connection when you're done with it.
    conn.Close()
}
客户端只发送一个大的http请求或一个限制的请求。 我希望在第一批包裹到达后,能很快打印出“有东西了”,但这不是我看到的。例如,对于节流客户机,我将把所有的包放在一起,只有在完整的包到达后才打印“gottsomething”

Go中限制客户端的代码:

reader, writer := io.Pipe()
request, _ := http.NewRequest("PUT", URL, reader)
request.Header = http.Header{}
request.Header["Connection"]=[]string {"keep-alive"}
request.Header["X-Content-Type-Options"]=[]string {"nosniff"}
request.Header["Accept-Encoding"]=[]string{"gzip, deflate"}
request.Header["Accept"]=[]string{"*/*"}
request.Header["Transfer-Encoding"]=[]string {"chunked"}
request.TransferEncoding=[]string {"chunked"}

//puts one byte in 100ms asynchronously
go func(w *io.PipeWriter){
    i:=0
    for true {
        i+=1
        w.Write([]byte{0})
        time.Sleep(100 * time.Millisecond)
        fmt.Print("-")
        if i > 1000 {
            w.CloseWithError(io.EOF)
            break
        }
    }
}(writer)

http.DefaultClient.Do(request)

如果您可以在这里添加代码,这样就有人可以对其进行评论,这会有所帮助。您好@AlexdaSilva,我添加了一个测试示例,希望它足够清晰。非常感谢你的帮助。