Skip to content

net/http/httputil: io.Copy in function of ReverseProxy is not high efficiency #10277

@heidawei

Description

@heidawei

in funtion

func (p *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {
    if p.FlushInterval != 0 {
        if wf, ok := dst.(writeFlusher); ok {
            mlw := &maxLatencyWriter{
                dst:     wf,
                latency: p.FlushInterval,
                done:    make(chan bool),
            }
            go mlw.flushLoop()
            defer mlw.stop()
            dst = mlw
        }
    }

    io.Copy(dst, src)
}

in boom test the QPS is 160000, but use another way like this:

func (p *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) {
    if p.FlushInterval != 0 {
        if wf, ok := dst.(writeFlusher); ok {
            mlw := &maxLatencyWriter{
                dst:     wf,
                latency: p.FlushInterval,
                done:    make(chan bool),
            }
            go mlw.flushLoop()
            defer mlw.stop()
            dst = mlw
        }
    }
        //now i Ignore the err temporary
    payload, err := ioutil.ReadAll(src)
    n, err := dst.Write(payload)
}

in boom test the QPS is 190000.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions