搭建高性能web服务
2015-11-04 20:42
495 查看
要求:
安装实验环境与工具:nginx、gunicorn、gevent、curl、ab(apache 压力测试工具)等等
测试用程序: 自学教程 4.2 读写字典服务 definitions_readwrite.py。 请按需要在此基础上改写程序,必须使用 MongoDB 数据库。
准备 4 台电脑,记录下每台电脑配置。其中一台,安装 MongoDB ,不提供其他服务。
使用测试工具,测试单进程同步、Tornado 异步(需要改写程序和异步驱动)、GEvent 异步(需要使用wsgi方式启动)方式的性能。
使用测试工具,将前一步骤性能最好的方式,与多进程、多线程同步方式(用gunicorn wsgi方式启动)对比性能。
用 4 台电脑,组成一个性能最强的 web 服务
相关代码:
definitions_readwrite.py
View Code
环境配置:
$sudo pip install gunicorn
$sudo pip install greenlet
$sudo pip install eventlet
$sudo pip install gevent
$sudo apt-get install apache2-utils (用于压力测试)
实验步骤:
UML部署图:
以下的测试均在测试量为10000,并发量为100的情况下进行
1)进行单进程同步压力测试
a)在A机上开启Mongodb服务, 命令如下:mongod.exe --dbpath "C:\Program Files\MongoDB\data\db" ;
b)在B机中启动nginx;
c)在C机, B机,D机中都运行python definition_readwrite.py作为应用服务器
e)在C机中进行压力测试,命令为ab ab -n 1000 -c 10 http://localhost/ (localhost和端口号需要换成代理机的IP和端口号)
f)可查看测试结果
2)其他的测试也类似,其中可通过查看如下的测试结果图比较
截图:
单进程同步:
tornado异步:
Gevent
多进程同步:
多线种同步:
说明 :1)要本地运行gunicorn时的命令一般为gunicorn code:application; 这样启动gunicorn,其默认作为一个监听127.0.01:8000的web server,可以通过本机访问,如果需要通过网络来访问gunicorn服务的话,需要使用-b命令来绑定不同的地址,同时设置监听端口,也就是需要使 用本机在网络中的IP地址加端口号;
2)修改程序为tornado异步的,不仅方式要是异步的,同时也需要使用异步的mongodb;
3) 用gevent运行程序,会自动将同步的程序的每个进程使其都支持IO阻塞异步的。
安装实验环境与工具:nginx、gunicorn、gevent、curl、ab(apache 压力测试工具)等等
测试用程序: 自学教程 4.2 读写字典服务 definitions_readwrite.py。 请按需要在此基础上改写程序,必须使用 MongoDB 数据库。
准备 4 台电脑,记录下每台电脑配置。其中一台,安装 MongoDB ,不提供其他服务。
使用测试工具,测试单进程同步、Tornado 异步(需要改写程序和异步驱动)、GEvent 异步(需要使用wsgi方式启动)方式的性能。
使用测试工具,将前一步骤性能最好的方式,与多进程、多线程同步方式(用gunicorn wsgi方式启动)对比性能。
用 4 台电脑,组成一个性能最强的 web 服务
相关代码:
definitions_readwrite.py
#user nginx; worker_processes 4; error_log /var/log/nginx/error.log; pid /var/run/nginx.pid; events { worker_connections 4096; use epoll; } http { # Enumerate all the Tornado servers here upstream frontends { server 172.18.43.53:8001 weight=3; server 172.18.42.169:8001 weight=4; server 172.18.43.132:8001 weight=3; } include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; keepalive_timeout 65; proxy_read_timeout 200; sendfile on; tcp_nopush on; tcp_nodelay on; gzip on; gzip_min_length 1000; gzip_proxied any; gzip_types text/plain text/html text/css text/xml application/x-javascript application/xml application/atom+xml text/javascript; # Only retry if there was a communication error, not a timeout # on the Tornado server (to avoid propagating "queries of death" # to all frontends) proxy_next_upstream error; server { listen 80; # Allow file uploads client_max_body_size 50M; location ^~ /static/ { root /var/www; if ($query_string) { expires max; } } location = /favicon.ico { rewrite (.*) /static/favicon.ico; } location = /robots.txt { rewrite (.*) /static/robots.txt; } location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://frontends; } } }
View Code
环境配置:
$sudo pip install gunicorn
$sudo pip install greenlet
$sudo pip install eventlet
$sudo pip install gevent
$sudo apt-get install apache2-utils (用于压力测试)
实验步骤:
UML部署图:
以下的测试均在测试量为10000,并发量为100的情况下进行
1)进行单进程同步压力测试
a)在A机上开启Mongodb服务, 命令如下:mongod.exe --dbpath "C:\Program Files\MongoDB\data\db" ;
b)在B机中启动nginx;
c)在C机, B机,D机中都运行python definition_readwrite.py作为应用服务器
e)在C机中进行压力测试,命令为ab ab -n 1000 -c 10 http://localhost/ (localhost和端口号需要换成代理机的IP和端口号)
f)可查看测试结果
2)其他的测试也类似,其中可通过查看如下的测试结果图比较
截图:
单进程同步:
tornado异步:
Gevent
多进程同步:
多线种同步:
说明 :1)要本地运行gunicorn时的命令一般为gunicorn code:application; 这样启动gunicorn,其默认作为一个监听127.0.01:8000的web server,可以通过本机访问,如果需要通过网络来访问gunicorn服务的话,需要使用-b命令来绑定不同的地址,同时设置监听端口,也就是需要使 用本机在网络中的IP地址加端口号;
2)修改程序为tornado异步的,不仅方式要是异步的,同时也需要使用异步的mongodb;
3) 用gevent运行程序,会自动将同步的程序的每个进程使其都支持IO阻塞异步的。
相关文章推荐
- jQuery学习实例:瀑布流布局
- React Native
- 类之间的覆盖问题
- DevExpress的NavBarControl组件中NavBarGroup如何触发展开或者折叠事件(点击事件)?
- 光栅化三维场景的基本流程
- 程序员学习交流的网站论坛
- linux设置root用户的密码
- C# 时间转换 Windows的toFileTimeutc时间转换
- Android之Fragment创建方式
- Spring框架简介---依赖注入和控制反转
- 字符串---不使用库函数,编写函数strcpy
- Linux 创建消息队列时出现 No space left on device的处理方法
- Invert Binary Tree
- 画廊插件
- mongodb
- 部署redis集群的一些思考
- Java环境与语法
- Matlab中graphmaxflow函数的用法
- java 线程
- IEnumerable<T> 接口和GetEnumerator 详解