1.安装flask

pip install flask

2.安装gevent

pip install gevent

3.安装gunicorn

pip install gunicorn

版本信息例如以下:

[root@rs-2 ~]# pip list

Flask (0.10.1)

gevent (1.0.1)

greenlet (0.4.2)

gunicorn (18.0)

pip (1.5.5)

setuptools (3.6)

4.安装nginx

下载源代码包安装,版本号信息例如以下

[root@rs-2 sbin]# ./nginx -v

nginx version: nginx/1.7.0

5.nginx配置反向代理

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

try_files @uri @pp;

}

location @pp {

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_pass http://127.0.0.1:5000;

}

全部请求转发到gunicorn监听的5000上。

6.gunicorn配置

[root@rs-2 pythonTest]# cat gun.conf

import os

bind='127.0.0.1:5000'

workers=4

backlog=2048

worker_class="gevent" #sync, gevent,meinheld

debug=True

proc_name='gunicorn.pid'

pidfile='/var/log/gunicorn/debug.log'

loglevel='debug'

[root@rs-2 pythonTest]#

7.測试脚本编写

[root@rs-2 pythonTest]# cat run_test.py

from flask import Flask
from flask import render_template_string import os from werkzeug.contrib.fixers import ProxyFix app = Flask(__name__) @app.route("/")
def index():
return "Hello World" app.wsgi_app = ProxyFix(app.wsgi_app)
if __name__ == "__main__":
app.run()

8.启动脚本

[root@rs-2 pythonTest]# gunicorn -c gun.conf  run_test:app


看到例如以下部分输入

2014-05-12 10:29:41 [30260] [INFO] Listening at: http://127.0.0.1:5000 (30260)

2014-05-12 10:29:41 [30260] [INFO] Using worker: gevent

2014-05-12 10:29:41 [30265] [INFO] Booting worker with pid: 30265

2014-05-12 10:29:41 [30266] [INFO] Booting worker with pid: 30266

2014-05-12 10:29:41 [30267] [INFO] Booting worker with pid: 30267

2014-05-12 10:29:41 [30268] [INFO] Booting worker with pid: 30268

监听本机的5000port,

工作模式为gevent,

开启4个进程

9.压力測试

在还有一台虚拟上进行用ab模拟并发请求

报错:apr_socket_recv: No route to host (113)

[root@rs-1 ~]# time ab -n 200 -c 200 http://172.16.3.92/

This is ApacheBench, Version 2.3 <$Revision: 1554214 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.16.3.92 (be patient)

apr_socket_recv: No route to host (113)

real 0m0.078s

user 0m0.021s

sys 0m0.046s


解决方法:关闭目标server的防火墙

[root@rs-2 pythonTest]# service iptables stop

Flushing firewall rules:                                   [  OK ]

Setting chains to policy ACCEPT: filter                    [  OK ]

Unloading iptables modules:                                [  OK ]

ok, 这下能够压力測试了

[root@rs-1 ~]# time ab -n 2000 -c 200 http://172.16.3.92/

This is ApacheBench, Version 2.3 <$Revision: 1554214 $>

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.16.3.92 (be patient)

Completed 200 requests

Completed 400 requests

Completed 600 requests

Completed 800 requests

Completed 1000 requests

Completed 1200 requests

Completed 1400 requests

Completed 1600 requests

Completed 1800 requests

Completed 2000 requests

Finished 2000 requests

Server Software:        nginx/1.7.0

Server Hostname:        172.16.3.92

Server Port:            80

Document Path:          /

Document Length:        11 bytes

Concurrency Level:      200

Time taken for tests:   16.273 seconds

Complete requests:      2000

Failed requests:        0

Total transferred:      334000 bytes

HTML transferred:       22000 bytes

Requests per second:    122.90 [#/sec] (mean)

Time per request:       1627.313 [ms] (mean)

Time per request:       8.137 [ms] (mean, across all concurrent requests)

Transfer rate:          20.04 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0   40 486.7      1    8992

Processing:   276 1032 250.5   1028    6300

Waiting:      273 1032 250.5   1027    6300

Total:        283 1072 618.1   1029   15292

Percentage of the requests served within a certain time (ms)

50%   1029

66%   1055

75%   1074

80%   1096

90%   1210

95%   1245

98%   1361

99%   2416

100%  15292 (longest request)

real 0m16.316s

user 0m0.598s

sys 0m1.447s

flask+gevent+gunicorn+nginx 初试的更多相关文章

  1. flask +gevent+nginx+Gunicorn+supervisor部署flask应用

    上篇   可以完美部署flask ,但是视乎在结合gevent+apscheduler 实现异步非阻塞后台和定时任务的时候视乎不是那么完美.请教了前辈,决定使用flask+gevent+nginx+g ...

  2. 基于flask+gunicorn+nginx来部署web App

    基于flask+gunicorn&&nginx来部署web App WSGI协议 Web框架致力于如何生成HTML代码,而Web服务器用于处理和响应HTTP请求.Web框架和Web服务 ...

  3. 【新手向】阿里云上ubuntu+flask+gunicorn+nginx服务器部署(二)项目部署

    本项目实现的是类似于ins的图片分享网站.继续(一),当nginx的配置已修改好后,要在远程服务器上部署网站,只需要几个步骤: 1 前期准备 2 将运行网站的代码从github上下载过来 3 下载依赖 ...

  4. Django + Gunicorn + Nginx 部署之路

    前言 最近,我已经成功将我的个人网站从 Flask 迁移到 Django 了,最早接触 Django 的时候大概是在 4 年前,我记得那个时候 Django 中的路由配置使用 正则 来进行的,但是我有 ...

  5. Flask+gevent 异步 WEB 架构

    :first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; m ...

  6. gunicorn+nginx配置方法

    对于gunicorn+nginx的配置,理解他们之间的关系很重要,以及最后如何确认配置结果是正确的也很重要 nginx 配置文件: 修改这个配置文件有3个用处: 假设服务器本身的Ip是A称为ip-A, ...

  7. 11: Django + gunicorn + Nginx 的生产环境部署

    1.1 gunicorn介绍   1.Gunicorn 1. Gunicorn是使用Python实现的WSGI服务器, 直接提供了http服务, 并且在woker上提供了多种选择, gevent, e ...

  8. 初次部署django+gunicorn+nginx

    初次部署django+gunicorn+nginx  博客详细地址  https://www.cnblogs.com/nanrou/p/7026802.html 写在前面,这只是我所遇到的情况,如果有 ...

  9. Django + Gunicorn + Nginx 部署 Ubuntu 服务器

    Django + Gunicorn + Nginx 部署服务器 获取腾讯云 root权限 本人的服务器使用的是腾讯云,腾讯云默认是没有开放 root 用户的,我们来创建 root 用户. 创建 roo ...

随机推荐

  1. hdu2606(递推)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2606 题意:  用1*1,2*2,3*3,4*4的正方形填充4*n的矩形, 问有多少种不同填法. 分析 ...

  2. 陈一舟《情系人人》:先搞钱,再搞人才_DoNews-IT门户-移动互联网新闻-电子商务新闻-游戏新闻-风险投资新闻-IT社交网络社区

    陈一舟<情系人人>:先搞钱,再搞人才_DoNews-IT门户-移动互联网新闻-电子商务新闻-游戏新闻-风险投资新闻-IT社交网络社区 陈一舟<情系人人>:先搞钱,再搞人才

  3. 【剑指offer】复制的复杂链条

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/26154691 题目描写叙述: 输入一个复杂链表(每一个节点中有节点值,以及两个指针,一个指 ...

  4. IOS程序设相关计开发技巧

    iOS programming architecture and design guidelines 原文地址:http://blog.mugunthkumar.com/articles/ios-pr ...

  5. android旋转动画和平移动画具体解释,补充说一下假设制作gif动画放到csdn博客上

    先上效果图: 我这里用的是GifCam来制作的gif动画,能够在http://download.csdn.net/detail/baidu_nod/7628461下载, 制作过程是先起一个模拟器,然后 ...

  6. swfobject.js的简单配置

    因为工作需要在网页中迁入flash,开发过程中,发现直接使用embed自己开发的话需要考虑各种兼容性,也比较麻烦, 网上也找了几个相关的插件,比较使用之下,发现swfobject.js这一款还是蛮不错 ...

  7. Linux系统部署规范v1.0

    Linux系统部署规范v1.0 目的: 1.尽可能减少线上操作: 2.尽可能实现自动化部署: 3.尽可能减少安装服务和启动的服务: 4.尽可能使用安全协议提供服务: 5.尽可能让业务系统单一: 6.尽 ...

  8. Sort方法的扩展

    OC中类方法中仅仅为我们提供了一些降序方法,如今我们自定义方法,实现升序. 1.要求:定义一个Person类,实例变量包含name,age,height,定义几个对象,把这些对象保存在数组中,自定义方 ...

  9. UVALive - 4621 Cav 贪心 + 分析

    题目大意:有一张洞穴地图,要在这个洞穴里面存放水,要求水不能碰到洞穴顶部.如今给出每一个位置的顶部位置和地面高度.问最多能够放多少水 解题思路:根据物理定理,每一段有水的连续区间,水位高度必须相等 所 ...

  10. android中listview分页载入数据

    前段时间做的新浪微博项目一直想实现listview分页载入数据,今天最终实现了,哈哈!感觉挺好的,今天又写了个demo给大家分享下. 首先说下listview的优化方案,这也是面试中常考的题目.优化方 ...