Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!