`
jinghong
  • 浏览: 55639 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nginx,uwsgi,bottle,virtualenv在centos6上安装及性能测试

阅读更多
终于决定废弃java而使用python来开发网站,测试web.py的性能有点失望,看到bottle性能不错,也满足我们的需求,符合python simple的理念。测试一下生产环境的性能。
参照http://studio.zeuik.com/?p=791
测试机器:X5650X2,48G内存,centos6,包括nginx,uwsgi
压测机器:X5680X2,96G内存
web.py把cpu几乎用尽的情况下也就5000req/s左右。

1、获取安装文件
nginx-1.0.10.tar.gz
uwsgi-0.9.9.2.tar.gz
virtualenv-1.6.4.tar.gz
bottle-0.10.1.tar.gz
2、安装nginx
tar zxvf nginx-1.0.10.tar.gz 
cd nginx-1.0.10
./configure --prefix=/usr/local/nginx --with-select_module --with-poll_module --with-http_ssl_module --with-http_gzip_static_module --with-http_flv_module --with-http_sub_module --with-http_stub_status_module --with-http_secure_link_module
make && make install

配置nginx配置文件
/usr/local/nginx/conf/nginx.conf
worker_processes 8; #24线程cpu,8个nginx,16个uwsgi
events {
    worker_connections  10240;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen      80;
        charset     utf-8;
        root        /application/venv/bottletest;
        server_name cow.com;
 
        location / {
            include uwsgi_params;
            uwsgi_param UWSGI_PYHOME /application/venv/bottletest;
            uwsgi_param UWSGI_CHDIR /application/venv/bottletest;
            uwsgi_param UWSGI_SCRIPT index; # 对应index.py
            uwsgi_pass  127.0.0.1:8888;
        }   
 
        location ^~ /static {
            root /application/venv/bottletest;
            access_log off;
        }   
 
        location /status {
            stub_status on;
            access_log  off;
        }
    }  
} 

3、安装uwsgi
tar zxvf uwsgi-0.9.9.2.tar.gz 
cd uwsgi-0.9.9.2
mkdir /usr/local/uwsgi
cp uwsgi /usr/local/uwsgi/
cp uwsgi.xml /usr/local/uwsgi/bottletest.xml
chown root:wheel /usr/local/uwsgi/logs

配置uwsgi的xml格式配置文件
/usr/local/uwsgi/bottletest.xml
<uwsgi>
    <socket>127.0.0.1:8888</socket>
    <home>/application/venv/bottletest</home>
    <chdir>/application/venv/bottletest</chdir>
    <python-path>/application/venv/bottletest</python-path>
    <module>[WSGI Script (index)]</module>
    <limit-as>256MB</limit-as>
    <processes>16</processes> <!-- 进程数 -->
    <master/>
    <memory/>
    <logto>/usr/local/uwsgi/logs/bottletest.log</logto>
    <daemonize>/var/log/uwsgi.log</daemonize>
    <max-requests>10000</max-requests>
</uwsgi>

4、安装virtualenv并创建bottletest应用
tar zxvf virtualenv-1.6.4.tar.gz 
cd virtualenv-1.6.4
python setup.py install
/usr/bin/virtualenv /application/venv/bottletest
cd /application/venv/bottletest
source bin/activate

5、编辑python文件
/application/venv/bottletest/index.py
from bottle import route, run, default_app
@route('/')
def index():
        return "hello world"
if __name__ == "__main__":
        run(host="localhost", port=8888)
else:
        application = default_app()


6、启动nginx和uwsgi
/usr/local/nginx/sbin/nginx
/usr/local/uwsgi/uwsgi -x /usr/local/uwsgi/bottletest.xml


7、ab测试结果
100 client
ab -c 100 -n 100000 http://192.168.0.90/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.90 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        nginx/1.0.10
Server Hostname:        192.168.0.90
Server Port:            80

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      100
Time taken for tests:   4.891 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      16800336 bytes
HTML transferred:       1100022 bytes
Requests per second:    20443.76 [#/sec] (mean)
Time per request:       4.891 [ms] (mean)
Time per request:       0.049 [ms] (mean, across all concurrent requests)
Transfer rate:          3354.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.7      1      15
Processing:     1    4   1.8      4     134
Waiting:        1    4   1.9      4     134
Total:          1    5   1.8      5     135

Percentage of the requests served within a certain time (ms)
  50%      5
  66%      5
  75%      5
  80%      5
  90%      6
  95%      6
  98%      8
  99%     13
 100%    135 (longest request)


1000 client
ab -c 1000 -n 100000 http://192.168.0.90/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.90 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        nginx/1.0.10
Server Hostname:        192.168.0.90
Server Port:            80

Document Path:          /
Document Length:        11 bytes

Concurrency Level:      1000
Time taken for tests:   9.057 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      16800000 bytes
HTML transferred:       1100000 bytes
Requests per second:    11040.71 [#/sec] (mean)
Time per request:       90.574 [ms] (mean)
Time per request:       0.091 [ms] (mean, across all concurrent requests)
Transfer rate:          1811.37 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9 114.9      4    3007
Processing:     1   51 372.0     12    9028
Waiting:        0   50 372.1     10    9028
Total:          3   60 389.4     16    9043

Percentage of the requests served within a certain time (ms)
  50%     16
  66%     19
  75%     21
  80%     22
  90%     26
  95%     31
  98%     50
  99%   3006
 100%   9043 (longest request)

webbench模拟1000和5000客户端测试,系统负载都在4左右
1000 client
./webbench -t 30 -c 1000 http://192.168.0.90/
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.0.90/
1000 clients, running 30 sec.

Speed=1195526 pages/min, 3347411 bytes/sec.
Requests: 597753 susceed, 10 failed.

5000 client
./webbench -t 30 -c 5000 http://192.168.0.90/ 
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.0.90/
5000 clients, running 30 sec.

Speed=1209354 pages/min, 3383884 bytes/sec.
Requests: 604269 susceed, 408 failed.


总结
性能基本满意,回头测试一下模板cheetah和mako的性能。
再测试一下nginx upstreaming tornado的性能,看是否能作为nginx c module某些功能的替代品
分享到:
评论

相关推荐

    离线部署uwsgi和nginx所需包

    本篇将详细讲解如何在Linux CentOS系统上,利用离线模式部署uwsgi和nginx来支持Django项目的运行。 首先,uwsgi是一个高效且可扩展的Python应用服务器,它允许我们将Python应用程序(如Django)作为服务运行。uwsgi...

    centos下使用Nginx+uWsgi部署Python Flask项目的详细配置

    现在,你的Flask应用应该可以通过Nginx和uWsgi在CentOS上正常运行。你可以访问`http://your_domain.com`来测试部署是否成功。 在整个过程中,注意文件权限和路径的正确性,以及确保防火墙允许Nginx和uWsgi的通信。...

    Centos8下django项目部署 nginx+uwsgi的教程

    在本教程中,我们将深入探讨如何在CentOS 8操作系统上部署Django项目,利用Nginx作为反向代理服务器,以及uWSGI作为应用服务器。这个过程涉及到多个步骤,包括虚拟环境的创建、Django项目的配置、uWSGI的安装与配置...

    nginx+uwsgi+mysql+python

    测试 Uwsgi 是否安装成功: 1. 新建一个 uwsgiTest.py 文件,代码如下: ``` # -*- coding:utf-8 -*- def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return ...

    flask+uwsgi+nginx部署.pdf

    通过以上步骤,您已经成功地在CentOS上安装了Python 3.7,并使用uWSGI和Nginx部署了一个基于Flask的应用。这种部署方式能够有效地提高Web应用的性能和稳定性。请注意,在生产环境中还需要进一步优化和安全配置,例如...

    django3.0.3+uwsgi+nginx+MySql在CentOS7上环境部署

    本文主要介绍如何在CentOS7操作系统上搭建一个基于Django 3.0.3、uWSGI、Nginx和MySQL 8.0.19的Web开发环境。以下是每个组件的详细说明及部署步骤: 1. Django 3.0.3: Django是一个高级的Python Web框架,用于快速...

    阿里云部署python+flask+uwsgi+gevent+nginx

    在阿里云上部署Python Flask应用程序,通常会结合使用uwsgi、gevent和nginx来实现高效率和高性能的服务。这里我们将详细讲解如何在CentOS 8操作系统上进行这一过程。 首先,我们创建一个新的用户,例如“python”,...

    Django 部署 centos7.rar

    在CentOS 7上部署Django项目,我们需要经历一系列步骤,包括安装Python环境、配置虚拟环境、安装Django、设置数据库、配置Nginx和uWSGI等。以下是详细的部署过程: 1. **安装Python与pip** CentOS 7默认的Python...

    Django项目uwsgi+Nginx保姆级部署教程实现

    在这个教程中,我们使用的环境是CentOS 7.5,Python 3.6.5,Nginx 1.16.1,以及uwsgi 2.0.18。若你的环境不同,可能需要根据实际情况调整配置。 **环境准备** 在部署之前,确保已安装Python虚拟环境,这可以帮助...

    云主机部署文档1

    1. **CentOS 安装与Nginx配置** - CentOS 7是CentOS的一个版本,提供了丰富的软件包管理工具yum,使得安装软件变得更加简单。 - 要安装Nginx,首先需要添加Nginx的官方YUM资源库。通过执行`sudo rpm -Uvh ...

    高精度地图监控平台项目部署1

    - **Nginx**:作为反向代理服务器,被安装在CentOS系统上。其位于/soft/目录下的二进制文件可以用来启动、停止和重载服务。在项目部署中,需要修改Nginx配置文件,添加一个新的server块监听89端口,设置uwsgi参数,...

    基于Django开发的next主题个人博客网站

    6. 部署:Nginx + uWSGI 在生产环境中,项目通常不会直接运行在开发服务器上,而是部署到云服务器。在这个项目中,选择了阿里云的CentOS 7系统作为服务器操作系统。Nginx是一个高性能的反向代理服务器,负责处理HTTP...

    一次flask+redis的微服务实战

    我们将依次介绍背景、操作系统升级、Python虚拟环境的创建、Nginx和uWSGI的配置、Redis的安装以及Python中使用Redis作为缓存的方法。 0x00 背景 项目的目标是开发一个类似知乎的垂直领域社区,主要服务于金融行业。...

    python基础知识-05-Linux内核和发行版.ev4.rar

    对于Python项目部署,Linux系统常作为Web服务器的基础,搭配Apache或Nginx等服务,使用Gunicorn、uWSGI等WSGI服务器,实现高效稳定的服务运行。 总的来说,学习Python基础知识时,了解Linux内核和发行版的重要性...

Global site tag (gtag.js) - Google Analytics