Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
XHR HTTP request performance between Python Flask and JavaScript

During benchmarking tests, I noticed that sequential XHR HTTP requests between JavaScript and Python Flask are quite slow on Windows, with a factor 10 less of what I expected: only ~ 80 MB/sec between a Python Flask server and Chrome on the same computer (localhost). I have a rather standard i5 CPU.

Is there some obvious bottleneck or an obvious misuse of the API in the following code that make the XHR HTTP requests limited at less than 100 MB/sec on an average computer?

import time, flask, numpy as np
app = flask.Flask("Test")
i, b, t0 = 0, 0, time.time()
x = np.random.rand(1000,1000).tobytes()  # fixed bytes to avoid measuring the random generation time
                                         # 7.6 MB
@app.route('/data')
def data():
    global i, b
    i += 1
    b += len(x)
    if i % 10 == 0:
        print("%.1f MB, %.1f MB/sec" % (b / 2**20, b / 2**20 / (time.time()-t0)))
    return x
@app.route('/')
def index():
    return """
<html><head></head><body><script>
function getdata() {
    req = new XMLHttpRequest();
    req.open("GET", "/data", true);
    req.responseType = "arraybuffer";
    req.onload = function (oEvent) {
        var arrayBuffer = req.response;
        if (arrayBuffer) {
            // var byteArray = new Uint8Array(arrayBuffer);
            getdata();       // sequential: new request only when the previous data has arrived
        }
    };
    req.send(null);
}
getdata();
</script></body></html>
"""
app.run()

(Run the script, go on http://127.0.0.1:5000/ and check the Python log).

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda