pyserve
1.0.0
Python에서 구현 된 단일 파일 CGI 서버.
다음 내용으로 hello.py 라는 새 파일을 만듭니다.
#!/usr/bin/env python3
from pyserve import http
print ( f"Hi { http . GET [ 'name' ] } !" )사용하지 않더라도 Pysest를 가져와야합니다. 그렇지 않으면 스크립트에 대한 올바른 HTTP 헤더를 명시 적으로 작성해야합니다.
파일 실행 파일 만들기 :
chmod +x hello.py서버 시작 :
python3 pyserve.py http://localhost:8000/hello.py?name=Meir 를 개방하십시오.
다음 출력이 표시됩니다.
Hi! ['Meir']
각 요청마다 새로운 프로세스가 생성되기 때문에 성능은 그리 좋지 않습니다.
#!/usr/bin/env python3
import pyserve
print ( "Hello World!" ) ab -n 500 -c 50 http://127.0.0.1:8000/hello_world.py
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /hello_world.py
Document Length: 13 bytes
Concurrency Level: 50
Time taken for tests: 6.108 seconds
Complete requests: 500
Failed requests: 0
Total transferred: 38500 bytes
HTML transferred: 6500 bytes
Requests per second: 81.86 [#/sec] (mean)
Time per request: 610.768 [ms] (mean)
Time per request: 12.215 [ms] (mean, across all concurrent requests)
Transfer rate: 6.16 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.7 0 5
Processing: 88 591 150.9 569 993
Waiting: 87 570 146.2 548 990
Total: 89 591 151.1 569 993
Percentage of the requests served within a certain time (ms)
50% 569
66% 648
75% 700
80% 724
90% 777
95% 848
98% 959
99% 962
100% 993 (longest request)
초당 ~ 80 개의 요청 만 있습니다. 플라스크와 비교해 봅시다.
from flask import Flask
app = Flask ( __name__ )
@ app . route ( "/" )
def ping ():
return "Hello World!" ab -n 500 -c 50 http://127.0.0.1:8000/
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 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: gunicorn
Server Hostname: 127.0.0.1
Server Port: 8000
Document Path: /
Document Length: 12 bytes
Concurrency Level: 50
Time taken for tests: 0.158 seconds
Complete requests: 500
Failed requests: 0
Total transferred: 82500 bytes
HTML transferred: 6000 bytes
Requests per second: 3157.24 [#/sec] (mean)
Time per request: 15.837 [ms] (mean)
Time per request: 0.317 [ms] (mean, across all concurrent requests)
Transfer rate: 508.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 2
Processing: 2 15 4.0 13 28
Waiting: 1 15 4.0 13 28
Total: 4 15 4.1 13 29
Percentage of the requests served within a certain time (ms)
50% 13
66% 14
75% 16
80% 18
90% 22
95% 25
98% 27
99% 28
100% 29 (longest request)
참고 : gunicorn app:app 으로 서버를 실행합니다.
~ 3150 초당 요청 ( x40 배 더 빠른 ). 이것은 큰 차이이며, 근로자 수를 늘리면 더 나은 결과를 얻을 수 있습니다.