centos6.4 uWSGI + nginx + bottle (下)

配置uWSGI的服务方式启动

承接上文 centos6.4 uWSGI + nginx + bottle (上) ,此文主要是说配置uWSGI(将之前的/etc/rc.local 的追加script删除)

vi /etc/uwsgi3031.ini


[uwsgi]
socket = 127.0.0.1:3031
master = true
vhost = true
no-stie = true
workers = 2
reload-mercy = 10    
vacuum = true
max-requests = 1000  
limit-as = 512
buffer-sizi = 30000
pidfile = /var/run/uwsgi3031.pid
daemonize = /var/www/test_app/uwsgi3031.log




vi /etc/init.d/uwsgi3031
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'
### BEGIN INIT INFO
# Provides:          uwsgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the uwsgi web server
# Description:       starts uwsgi using start-stop-daemon
### END INIT INFO
# Author:   licess
# website:  http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi3031
DAEMON=/usr/bin/uwsgi
CONFIGFILE=/etc/$NAME.ini
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
    $DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
do_stop() {
    $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
    rm -f $PIDFILE
    echo "$DAEMON STOPED."
}
do_reload() {
    $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"
}
do_status() {
    ps aux|grep $DAEMON
}
case "$1" in
status)
    echo -en "Status $NAME: \n"
    do_status
;;
start)
    echo -en "Starting $NAME: \n"
    do_start
;;
stop)
    echo -en "Stopping $NAME: \n"
    do_stop
;;
reload|graceful)
    echo -en "Reloading $NAME: \n"
    do_reload
;;
*)
    echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
    exit 3
;;
esac
exit 0
在这个目录下一定要有执行权限



chmod +x /etc/init.d/uwsgi3031
配置一下开机启动服务



### add service
chkconfig --add uwsgi3031
chkconfig uwsgi3031 on
最后重启机器来试一下吧!



多个站点配置

按照上面的方法来配置多一个uWSGI,只不过是端口不同而已,以及在nginx的配置文件加入相应该的server节点就可以了,我下面直接来一个示例,将之前的代码复制一份叫test_app2,纯上代码的:

vi /etc/uwsgi9099.ini



[uwsgi]
socket = 127.0.0.1:9099
master = true
vhost = true
no-stie = true
workers = 2
reload-mercy = 10    
vacuum = true
max-requests = 1000  
limit-as = 512
buffer-sizi = 30000
pidfile = /var/run/uwsgi9099.pid
daemonize = /var/www/test_app2/uwsgi9099.log



vi /etc/init.d/uwsgi9099


#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for uwsgi webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f uwsgi defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add uwsgi'
### BEGIN INIT INFO
# Provides:          uwsgi
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the uwsgi web server
# Description:       starts uwsgi using start-stop-daemon
### END INIT INFO
# Author:   licess
# website:  http://lnmp.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="uwsgi daemon"
NAME=uwsgi9099
DAEMON=/usr/bin/uwsgi
CONFIGFILE=/etc/$NAME.ini
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
    $DAEMON $CONFIGFILE || echo -n "uwsgi already running"
}
do_stop() {
    $DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
    rm -f $PIDFILE
    echo "$DAEMON STOPED."
}
do_reload() {
    $DAEMON --reload $PIDFILE || echo -n "uwsgi can't reload"
}
do_status() {
    ps aux|grep $DAEMON
}
case "$1" in
status)
    echo -en "Status $NAME: \n"
    do_status
;;
start)
    echo -en "Starting $NAME: \n"
    do_start
;;
stop)
    echo -en "Stopping $NAME: \n"
    do_stop
;;
reload|graceful)
    echo -en "Reloading $NAME: \n"
    do_reload
;;
*)
    echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
    exit 3
;;
esac
exit 0


chmod +x /etc/init.d/uwsgi9099
vi /etc/nginx/conf.d/default.conf
## add one more server node, append this
server {
    listen       9999;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    location / {
       include uwsgi_params;
       uwsgi_param UWSGI_PYHOME /var/www/test_app2;
       uwsgi_param UWSGI_CHDIR /var/www/test_app2;
       uwsgi_param UWSGI_SCRIPT app;
       uwsgi_pass 127.0.0.1:9099;
       # root   /usr/share/nginx/html;
       # index  index.html index.htm;
    }
}

In the terminal:

##  add it to the service
chkconfig --add uwsgi9099
chkconfig uwsgi9099 on
## start the service
service uwsgi9099 start
## restart the nginx
service nginx restart



## you can try it out with curl or browser
curl http://127.0.0.1:9999/

简单的性能测试

我们就用Apache 的ab command line, ab 在linux/unix当中是默认是安装的,直接就可以用了,windows系统的话要另装。下面就直接来一下简单的压力测试吧!

#------------------------------------------------
#memory : 1024 MB
#cpu: Intel Core x 1
#尝试总共发10000个请求,10个并发(也就是相当于模拟10个人同时访问)
#------------------------------------------------
$ ab -c 10 -n 10000 http://192.168.1.99/
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.1.99 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:        nginx/1.4.4
Server Hostname:        192.168.1.99
Server Port:            80
Document Path:          /
Document Length:        21 bytes
Concurrency Level:      10
Time taken for tests:   10.711 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      1770000 bytes
HTML transferred:       210000 bytes
Requests per second:    933.61 [#/sec] (mean)
Time per request:       10.711 [ms] (mean)
Time per request:       1.071 [ms] (mean, across all concurrent requests)
Transfer rate:          161.38 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  33.1      0    1103
Processing:     1    9  17.8      9     564
Waiting:        1    9  17.8      9     564
Total:          1   11  37.5     10    1115
Percentage of the requests served within a certain time (ms)
  50%     10
  66%     10
  75%     10
  80%     10
  90%     11
  95%     11
  98%     12
  99%     13
100%   1115 (longest request)

在局域网内80% 的请求可以在 10 毫秒内响应,虚似的机器配置比较低(我的电脑也是3年前的没有办法),总共10000个请求还好,20000的话就比较免强了,有fail的可能了,再多就不行了。整体来说还算可以的。

参考


转载于:https://my.oschina.net/jackman/blog/313418

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值