uWSGI 只有1个进程工作

304 views
Skip to first unread message

Yuqiu Ye

unread,
Sep 15, 2018, 2:15:23 AM9/15/18
to python-cn(华蟒用户组,CPyUG 邮件列表)
uWSGI配置选项如下:

test.png

























用ps命令观察,结果如下

2.png


使用uwsgitop /tmp/stats.socket 监控各个worker:

3.png


可以看到,只有一个进程在工作,今天3个进程都是空闲的,是我的配置有问题吗? ps: uwsgi 版本为2.0.10


依云

unread,
Sep 17, 2018, 9:09:26 PM9/17/18
to pyth...@googlegroups.com
好不公平耶……你可以 strace 一下那几个空闲的 worker,看看它们都在干嘛。

--
Best regards,
lilydjwg

Linux Vim Python 我的博客:
https://blog.lilydjwg.me/
--
A: Because it obfuscates the reading.
Q: Why is top posting so bad?

Yuqiu Ye

unread,
Sep 18, 2018, 4:19:33 AM9/18/18
to python-cn(华蟒用户组,CPyUG 邮件列表)
我的项目架构是Nginx+uWSGI+Django,另外,使用APScheduler做任务调度,用来执行一些定时任务,APScheduler相关代码放在wsgi.py文件中

from apscheduler.schedulers.background import BackgroundScheduler
from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

sched = BackgroundScheduler()
sched.add_job(mail_function, 'interval',  minutes=1,  id='my_job_email')
sched.start()


现在的问题是,如果enable-threads开启,就会出现上述负载不均衡的情况,只有一个process处理请求,但是APScheduler的任务执行成功;如果关闭enable-threads,负载均衡就正常了,所有process都会处理请求,但是APScheduler中的任务却没有执行。

查看apscheduler官方文档,里面也提示要开启enable-threads。至于为什么跟enable-threads参数有关,还没搞明白,准备去看uWSGI源码了。

在 2018年9月18日星期二 UTC+8上午9:09:26,依云写道:

est

unread,
Sep 19, 2018, 11:44:58 PM9/19/18
to pyth...@googlegroups.com
APScheduler 根本不能放在 wsgi 模型下跑。。。
你要跑,放在一个 uWSGI mule 里,然后通过 uWSGI RPC 去交互。

然而如果你只是拿来做一些定时任务,uWSGI cron 了解一下。uWSGI RPC timer 了解一下。比什么 APScheduler 好用多了。

--
邮件来自: `CPyUG`华蟒用户组(中文Python技术邮件列表)
规则: http://code.google.com/p/cpyug/wiki/PythonCn
详情: http://code.google.com/p/cpyug/wiki/CpyUg
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
---
您收到此邮件是因为您订阅了Google网上论坛上的“python-cn(华蟒用户组,CPyUG 邮件列表)”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到python-cn+...@googlegroups.com
要发帖到此群组,请发送电子邮件至pyth...@googlegroups.com
要查看更多选项,请访问https://groups.google.com/d/optout

Chunlin Zhang

unread,
Sep 21, 2018, 10:05:12 AM9/21/18
to python-cn`CPyUG`华蟒用户组
我一般异步任务都喜欢用jenkins之类的去跑,比如定时就直接在jenkins里配置,需要触发异步任务就调用下jenkins的api
这样异步任务完成情况能看输出,异常又能收到邮件之类的
Reply all
Reply to author
Forward
0 new messages