1,访问效果
2,基本部署
启动脚本
nginx配置
hello.py
3,测试效果
测试I http://127.0.0.1:8000/hello
测试II http://python.i-david.org/hello
测试I是直接通过web.py框架访问hello.py程序的压力测试结果
测试II是通过nginx代理访问hello.py程序的压力测试结果
测试II在速度,吞吐率,请求成功数上都比直接访问要好
curl http://127.0.0.1:8000/hello
Hello World!d
curl http://python.i-david.org/hello
Hello World!d
2,基本部署
启动脚本
#!/bin/sh
ps -aux | grep 8000 | grep -v "grep" | awk '{print $2}' | xargs kill
python /home/david/python/test002/hello.py 127.0.0.1:8000 >/dev/null 2>&1 &
exit 0
nginx配置
server {
listen 80;
server_name python.i-david.org;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Remote-Host $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
hello.py
#!/usr/bin/python
# filename:hello.py
# -*- coding: UTF-8 -*-
import web
urls = ("/.*", "hello")
app = web.application(urls, globals())
class hello:
def GET(self):
return "Hello World!"
if __name__ == '__main__':
app.run()
3,测试效果
测试I http://127.0.0.1:8000/hello
webbench -c 100 -t 10 http://127.0.0.1:8000/hello
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1:8000/hello
100 clients, running 10 sec.
Speed=14772 pages/min, 21434 bytes/sec.
Requests: 2462 susceed, 0 failed.
测试II http://python.i-david.org/hello
webbench -c 100 -t 10 http://python.i-david.org/hello
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://python.i-david.org/hello
100 clients, running 10 sec.
Speed=16128 pages/min, 29990 bytes/sec.
Requests: 2688 susceed, 0 failed.
测试I是直接通过web.py框架访问hello.py程序的压力测试结果
测试II是通过nginx代理访问hello.py程序的压力测试结果
测试II在速度,吞吐率,请求成功数上都比直接访问要好