«   2018/06   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
337
Total
1,112,197
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

python helloWorld 본문

Language/Python

python helloWorld

푸른바람 C/H 2018.06.11 08:30

Python

#!/usr/bin/python
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer

PORT_NUMBER = 1337

class myHandler(BaseHTTPRequestHandler):
	
	#Handler for the GET requests
	def do_GET(self):
		self.send_response(200)
		self.send_header('Content-type','text/html')
		self.end_headers()
		# Send the html message
		self.wfile.write("Hello World !")
		return

try:
	#Create a web server and define the handler to manage the
	#incoming request
	server = HTTPServer(('', PORT_NUMBER), myHandler)
	print 'Started httpserver on port ' , PORT_NUMBER
	
	#Wait forever for incoming htto requests
	server.serve_forever()

except KeyboardInterrupt:
	print '^C received, shutting down the web server'
	server.socket.close()
python serve.py

# ohter terminal
ab -n 10000 -c 10 -k http://127.0.0.1:1337/
.....
Concurrency Level:      10
Time taken for tests:   1.554 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      1330000 bytes
HTML transferred:       130000 bytes
Requests per second:    6435.53 [#/sec] (mean)
Time per request:       1.554 [ms] (mean)
Time per request:       0.155 [ms] (mean, across all concurrent requests)
Transfer rate:          835.86 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0  20.4      0    1026
Processing:     0    1   4.6      1     415
Waiting:        0    1   4.6      1     415
Total:          0    1  23.8      1    1442

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      2
  98%      3
  99%      3
 100%   1442 (longest request)

Python bottle

sudo apt-get install python-pip
sudo pip install bottle
sudo apt-get install gunicorn
mkdir webapp
cd webapp
vi app.py
from bottle import Bottle, run

app = Bottle()

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

#run(app, host = 'localhost', port = 1337)
run(server = 'gunicorn', host='localhost', port=1337
python app.py
Bottle v0.12.13 server starting up (using WSGIRefServer())...
...

# other sell
ab -n10000 -c10 -g out.data -k http://127.0.0.1:1337/
...
Concurrency Level:      10
Time taken for tests:   2.736 seconds
Complete requests:      10000
Failed requests:        0
Non-2xx responses:      10000
Keep-Alive requests:    0
Total transferred:      8880000 bytes
HTML transferred:       7200000 bytes
Requests per second:    3654.52 [#/sec] (mean)
Time per request:       2.736 [ms] (mean)
Time per request:       0.274 [ms] (mean, across all concurrent requests)
Transfer rate:          3169.15 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     2    3   0.4      3       9
Waiting:        1    3   0.4      3       9
Total:          2    3   0.4      3       9

Percentage of the requests served within a certain time (ms)
  50%      3
  66%      3
  75%      3
  80%      3
  90%      3
  95%      3
  98%      4
  99%      5
 100%      9 (longest request)



'Language > Python' 카테고리의 다른 글

python helloWorld  (0) 2018.06.11
파이썬 라이브러리 가상환경 묶기  (0) 2017.05.16
Python 정규표현식 re  (0) 2016.12.12
python3 format() 서식화 메서드  (0) 2016.12.08
PyDev for Eclipse  (0) 2016.12.07
Python 문자열 변환 메서드  (0) 2016.12.05
0 Comments
댓글쓰기 폼