ab pressure test of java and python web

ab test of java and python web

Background introduction

The project plans to build a new system. Most of the project team are familiar with Python, so we consider using Python as the web background. Python is really simple. In these short days, I used Python to do crawlers, code generation tools, redash reports, airflow task scheduling, python called wechat webapi to implement robots, barrabarrabarra. It's really simple. It's easy to use, but it's not in-depth. And I always think that Python scripting language is used to develop web applications. How can I say that? It's not exciting. After all, java web is deeply rooted in the brain. And the organizers like Python as a scripting language and develop it quickly. So I took a look at Python's web framework and applied fastapi and tornado. Build a super simple web application.

Code

Are the most primitive, do not do anything to optimize anything, directly by the official website entry example.

fastapi

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def read_items():
    return 'Hello world'
    

tornado

import tornado.ioloop
import tornado.web


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")


def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
    ])


if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()

springboot

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ling
 * @date 2020/1/14
 * @copyright http://lostmylife.top/
 * @since
 */
@RestController
public class Controller {

    @GetMapping("/")
    public Object test(){
        return "Hello world";
    }

}

ab pressure measurement

ab is apache's own stress testing tool. The following syntax means
-n specifies the total number of times the stress test visits the page. The default is 1
-c is the number of concurrent requests generated at one time. The default value is 1
-r specifies not to exit the program when an error message is received

fastapi

ab  -n10000   -c 100 -r  http://127.0.0.1:8000/
......
Server Software:        uvicorn
Server Hostname:        127.0.0.1
Server Port:            8000
Document Path:          /
Document Length:        13 bytes
Concurrency Level:      100
Time taken for tests:   3.333 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      1380000 bytes
HTML transferred:       130000 bytes
Requests per second:    3000.31 [#/sec] (mean)
Time per request:       33.330 [ms] (mean)
Time per request:       0.333 [ms] (mean, across all concurrent requests)
Transfer rate:          404.34 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   2.4      1      86
Processing:     4   32  12.8     29     118
Waiting:        1   29  13.0     26     117
Total:          4   33  12.9     31     119

Percentage of the requests served within a certain time (ms)
  50%     31
  66%     31
  75%     32
  80%     33
  90%     35
  95%     45
  98%     98
  99%    108
 100%    119 (longest request)

tornado

ab  -n10000   -c 100 -r  http://127.0.0.1:8888/
......
Server Software:        TornadoServer/4.2
Server Hostname:        127.0.0.1
Server Port:            8888
Document Path:          /
Document Length:        12 bytes
Concurrency Level:      100
Time taken for tests:   5.454 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      2050000 bytes
HTML transferred:       120000 bytes
Requests per second:    1833.56 [#/sec] (mean)
Time per request:       54.539 [ms] (mean)
Time per request:       0.545 [ms] (mean, across all concurrent requests)
Transfer rate:          367.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0      20
Processing:     1   54   7.3     54     123
Waiting:        1   54   7.3     54     123
Total:          3   54   7.3     54     126

Percentage of the requests served within a certain time (ms)
  50%     54
  66%     56
  75%     58
  80%     58
  90%     61
  95%     64
  98%     69
  99%     70
 100%    126 (longest request)

springboot

ab  -n8000   -c 100 -r  http://127.0.0.1:8080/
......
Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   0.879 seconds
Complete requests:      8000
Failed requests:        0
Total transferred:      1152000 bytes
HTML transferred:       88000 bytes
Requests per second:    9103.55 [#/sec] (mean)
Time per request:       10.985 [ms] (mean)
Time per request:       0.110 [ms] (mean, across all concurrent requests)
Transfer rate:          1280.19 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    5   1.4      5      18
Processing:     1    6   1.9      6      20
Waiting:        1    5   1.7      5      18
Total:          4   11   2.0     11      25

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

conclusion

Although python's development of web applications is not as complicated as java's, python is one level faster in terms of configuration or code development efficiency, but in the case of intensive computing, its performance is not as good as java's. in the case of large applications, the code is not as clear at a glance as java's, and thanks to java's web application time structure, another programmer takes over in minutes. Of course, this is still the coding level of the programmer himself. The python code written by another person can be understood by others.
Generally speaking, javaweb is far better than python in performance

Published 8 original articles, won praise 32, visited 1637
Private letter follow

Tags: Python Java SpringBoot Apache

Posted on Tue, 14 Jan 2020 02:47:51 -0500 by cerebrus189