gpt4 book ai didi

linux - Supervisord 事件只发送给池中的一个事件监听器

转载 作者:太空宇宙 更新时间:2023-11-04 10:58:57 24 4
gpt4 key购买 nike

我正在使用 Event superervisord 中的协议(protocol)每 X 秒向我的每个进程发送一个“TICK”事件。问题是我想要运行这些进程的池 (numprocs=4),并且每个进程都接收信号。我看到的是只有一个进程实际接收到 TICK 信号,而其他进程什么也没接收到。

我已将问题简化为一个简单的 python 脚本。此脚本采用单个参数,用于为日志文件生成文件名。在日志文件中,记录了信号。我希望如果我使用 supervisord 启动这些脚本中的 4 个,那么我会得到 4 个日志文件,这些文件会随着时间的推移而增长。相反,我得到一个不断增长的文件。这是 python 脚本,event.py:

import sys


def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()

def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()

def write(name):
with open(name, 'a') as f:
f.write("signal\n")

def main():
if len(sys.argv) > 1:
name = "%s.txt" % sys.argv[1]
else:
name ="0.txt"

while 1:
write_stdout('READY\n') # transition from ACKNOWLEDGED to READY
line = sys.stdin.readline() # read header line from stdin
write_stderr(line) # print it out to stderr
write(name)
headers = dict([ x.split(':') for x in line.split() ])
data = sys.stdin.read(int(headers['len'])) # read the event payload
write_stderr(data) # print the event payload to stderr
write_stdout('RESULT 2\nOK') # transition from READY to ACKNOWLEDGED

if __name__ == '__main__':
main()
import sys

下面是我如何配置 supervisord 事件监听器:

[eventlistener:test]
numprocs=4
process_name=test-300%(process_num)02d
command=python /home/blah/event.py 300%(process_num)02d
directory=/home/blah
events=TICK_5
stopsignal=INT
stopwaitsecs=15
autostart=true
autorestart=true

以下是来自 supervisord 的日志:

$:) sudo tail -n500 /var/log/supervisor/*
==> /var/log/supervisor/supervisord.log <==
2014-12-29 16:45:12,752 CRIT Supervisor running as root (no user in config file)
2014-12-29 16:45:12,752 WARN Included extra file "/etc/supervisor/conf.d/supervisor-vpserver.conf" during parsing
2014-12-29 16:45:12,755 TRAC 127.0.0.1:Medusa (V1.12) started at Mon Dec 29 16:45:12 2014
Hostname: localhost
Port:9001
2014-12-29 16:45:12,785 INFO RPC interface 'supervisor' initialized
2014-12-29 16:45:12,786 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2014-12-29 16:45:12,786 TRAC /var/run/supervisor.sock:Medusa (V1.12) started at Mon Dec 29 16:45:12 2014
Hostname: <unix domain socket>
Port:/var/run/supervisor.sock
2014-12-29 16:45:12,786 INFO RPC interface 'supervisor' initialized
2014-12-29 16:45:12,786 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-12-29 16:45:12,787 BLAT supervisord forked; parent exiting
2014-12-29 16:45:12,787 INFO daemonizing the supervisord process
2014-12-29 16:45:12,788 INFO supervisord started with pid 15766
2014-12-29 16:45:13,791 INFO spawned: 'test-30002' with pid 15775
2014-12-29 16:45:13,793 INFO spawned: 'test-30003' with pid 15776
2014-12-29 16:45:13,795 INFO spawned: 'test-30000' with pid 15777
2014-12-29 16:45:13,798 INFO spawned: 'test-30001' with pid 15778
2014-12-29 16:45:13,817 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state STARTING> (stdout)>
2014-12-29 16:45:13,818 DEBG 'test-30002' stdout output:
READY

2014-12-29 16:45:13,818 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:13,819 BLAT read event caused by <PEventListenerDispatcher at 140274918531512 for <Subprocess at 140274918760528 with name test-30003 in state STARTING> (stdout)>
2014-12-29 16:45:13,819 DEBG 'test-30003' stdout output:
READY

2014-12-29 16:45:13,819 DEBG test-30003: ACKNOWLEDGED -> READY
2014-12-29 16:45:13,829 BLAT read event caused by <PEventListenerDispatcher at 140274918532088 for <Subprocess at 140274918706928 with name test-30000 in state STARTING> (stdout)>
2014-12-29 16:45:13,829 DEBG 'test-30000' stdout output:
READY

2014-12-29 16:45:13,829 DEBG test-30000: ACKNOWLEDGED -> READY
2014-12-29 16:45:13,829 BLAT read event caused by <PEventListenerDispatcher at 140274918532664 for <Subprocess at 140274918707072 with name test-30001 in state STARTING> (stdout)>
2014-12-29 16:45:13,829 DEBG 'test-30001' stdout output:
READY

2014-12-29 16:45:13,829 DEBG test-30001: ACKNOWLEDGED -> READY
2014-12-29 16:45:14,830 INFO success: test-30002 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:14,830 INFO success: test-30003 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:14,831 INFO success: test-30000 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:14,831 INFO success: test-30001 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-12-29 16:45:16,833 DEBG event 0 sent to listener test-30002
2014-12-29 16:45:16,833 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:16,833 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY

2014-12-29 16:45:16,833 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:16,833 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:16,834 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:16,834 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:0 pool:test poolserial:0 eventname:TICK_5 len:15
when:1419871515
2014-12-29 16:45:21,839 DEBG event 1 sent to listener test-30002
2014-12-29 16:45:21,839 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:21,840 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY

2014-12-29 16:45:21,840 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:21,840 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:21,840 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:21,840 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:1 pool:test poolserial:1 eventname:TICK_5 len:15
when:1419871520
2014-12-29 16:45:26,846 DEBG event 2 sent to listener test-30002
2014-12-29 16:45:26,846 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:26,846 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY

2014-12-29 16:45:26,846 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:26,846 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:26,846 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:26,846 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:2 pool:test poolserial:2 eventname:TICK_5 len:15
when:1419871525
2014-12-29 16:45:31,852 DEBG event 3 sent to listener test-30002
2014-12-29 16:45:31,852 BLAT read event caused by <PEventListenerDispatcher at 140274918461240 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stdout)>
2014-12-29 16:45:31,853 DEBG 'test-30002' stdout output:
RESULT 2
OKREADY

2014-12-29 16:45:31,853 DEBG test-30002: BUSY -> ACKNOWLEDGED (processed)
2014-12-29 16:45:31,853 DEBG test-30002: ACKNOWLEDGED -> READY
2014-12-29 16:45:31,853 BLAT read event caused by <POutputDispatcher at 140274918461384 for <Subprocess at 140274918707144 with name test-30002 in state RUNNING> (stderr)>
2014-12-29 16:45:31,853 DEBG 'test-30002' stderr output:
ver:3.0 server:supervisor serial:3 pool:test poolserial:3 eventname:TICK_5 len:15
when:1419871530

==> /var/log/supervisor/test-30000-stderr---supervisor-NystkJ.log <==

==> /var/log/supervisor/test-30000-stdout---supervisor-h4mTFE.log <==
READY

==> /var/log/supervisor/test-30001-stderr---supervisor-zJJKe7.log <==

==> /var/log/supervisor/test-30001-stdout---supervisor-936BaW.log <==
READY

==> /var/log/supervisor/test-30002-stderr---supervisor-NXzezy.log <==
ver:3.0 server:supervisor serial:0 pool:test poolserial:0 eventname:TICK_5 len:15
when:1419871515ver:3.0 server:supervisor serial:1 pool:test poolserial:1 eventname:TICK_5 len:15
when:1419871520ver:3.0 server:supervisor serial:2 pool:test poolserial:2 eventname:TICK_5 len:15
when:1419871525ver:3.0 server:supervisor serial:3 pool:test poolserial:3 eventname:TICK_5 len:15
when:1419871530
==> /var/log/supervisor/test-30002-stdout---supervisor-K_tGpa.log <==
READY
RESULT 2
OKREADY
RESULT 2
OKREADY
RESULT 2
OKREADY
RESULT 2
OKREADY

==> /var/log/supervisor/test-30003-stderr---supervisor-mOXclj.log <==

==> /var/log/supervisor/test-30003-stdout---supervisor-6Q521a.log <==
READY

在我看来,test-30002 是生成的 4 个进程中的第一个(最低 PID),因此它是接收事件的进程。所有其他人都被排除在外。这是使用 eventlistener 组和 numprocs > 1 时的已知行为吗?

更新:

我可能还应该添加这个:

$:) supervisord --version
3.0b2

最佳答案

如前所述,这对我来说很好 here并进行了更详细的描述 here ,池中只有一个进程应该获取每个事件,它可以是任何 READY 的进程。

如您所见,supervisord 只是在池中找到第一个不忙的。只要 TICK_5 事件的处理时间少于 5 秒,它就始终是第一个进程。

关于linux - Supervisord 事件只发送给池中的一个事件监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27692766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com