Skip to content

Instantly share code, notes, and snippets.

@yanqian
Last active May 29, 2024 04:07
Show Gist options
  • Save yanqian/47fce977e603f74de89a97439c847596 to your computer and use it in GitHub Desktop.
Save yanqian/47fce977e603f74de89a97439c847596 to your computer and use it in GitHub Desktop.
Benchmark on Go Http Server VS Python Flask

Prerequirement

Both run on my local machine.

Source Go

package main

import (
    "fmt"
    "net/http"
)

func hello(w http.ResponseWriter, req *http.Request) {
    fmt.Fprint(w, "Hello World!")
}

func main() {

    http.HandleFunc("/hello", hello)
    http.ListenAndServe(":8090", nil)
}

Go Result

QPS is 8962

➜  ~ ab -n 10000 -c 100  http://localhost:8090/
This is ApacheBench, Version 2.3 <$Revision: 1901567 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname:        localhost
Server Port:            8090

Document Path:          /
Document Length:        19 bytes

Concurrency Level:      100
Time taken for tests:   1.116 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Total transferred:      1760000 bytes
HTML transferred:       190000 bytes
Requests per second:    8962.61 [#/sec] (mean)
Time per request:       11.157 [ms] (mean)
Time per request:       0.112 [ms] (mean, across all concurrent requests)
Transfer rate:          1540.45 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    5   1.9      5      16
Processing:     0    6   2.7      6      28
Waiting:        0    5   2.0      5      26
Total:          2   11   3.2     10      33

Percentage of the requests served within a certain time (ms)
  50%     10
  66%     11
  75%     12
  80%     13
  90%     15
  95%     17
  98%     19
  99%     22
 100%     33 (longest request)

Source Python

#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
   return "Hello World!"

if __name__ == '__main__':
   app.run()

Python Result

QPS is 636

➜  ~ ab -n 10000 -c 100  http://127.0.0.1:5000/
This is ApacheBench, Version 2.3 <$Revision: 1901567 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:        Werkzeug/2.0.3
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   15.705 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1660000 bytes
HTML transferred:       120000 bytes
Requests per second:    636.75 [#/sec] (mean)
Time per request:       157.047 [ms] (mean)
Time per request:       1.570 [ms] (mean, across all concurrent requests)
Transfer rate:          103.22 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       8
Processing:     8  156  20.4    153     278
Waiting:        1  155  20.4    152     277
Total:          8  156  20.3    153     279

Percentage of the requests served within a certain time (ms)
 50%    153
 66%    158
 75%    163
 80%    166
 90%    174
 95%    189
 98%    219
 99%    240
100%    279 (longest request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment