0

这个问题特定于 Web2py 框架中的调度程序。

我将调度程序用作 Linux 服务。

我创建了一个文件 /etc/systemd/system/web2py-sched.service

[Unit]
Description=Web2Py scheduler service

[Service]
ExecStart=/usr/bin/python /home/www-data/web2py/web2py.py -K myApp
Type=simple
Restart=always
[Install]
WantedBy=multi-user.target

然后安装服务调用:

sudo systemctl enable /etc/systemd/system/web2py-sched.service 

systemctl start /etc/systemd/system/web2py-sched

当我检查我的 Postgres 状态时,我看到有些进程处于“Idle in Transaction”状态。

may@myApp:/home/www-data/web2py/scmyAppts$ sudo systemctl status postgresql@9.5-main
● postgresql@9.5-main.service - PostgreSQL Cluster 9.5-main
   Loaded: loaded (/lib/systemd/system/postgresql@.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-16 15:39:25 PDT; 1 weeks 1 days ago
 Main PID: 28202 (postgres)
   CGroup: /system.slice/system-postgresql.slice/postgresql@9.5-main.service
           ├─10956 postgres: may mydb ::1(60654) idle in transaction                                                                           
           ├─10957 postgres: may mydb ::1(60656) idle in transaction                                                                           
           ├─13421 postgres: may mydb 10.5.77.35(51998) idle                                                                                   
           ├─13422 postgres: may mydb 10.5.77.35(52004) idle                                                                                   
           ├─13423 postgres: may postgres 10.5.77.35(52005) idle                                                                               
           ├─13425 postgres: may mydb 10.5.77.35(52007) idle                                                                                   
           ├─13433 postgres: may mydb 10.5.77.35(52332) idle                                                                                   
           ├─28202 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf
           ├─28204 postgres: checkpointer process                                                                                              
           ├─28205 postgres: writer process                                                                                                    
           ├─28206 postgres: wal writer process                                                                                                
           ├─28207 postgres: autovacuum launcher process                                                                                       
           ├─28208 postgres: stats collector process                                                                                           
           ├─30475 postgres: may mydb ::1(59838) idle                                                                                          
           ├─30476 postgres: may mydb ::1(59840) idle in transaction                                                                           
           └─30500 postgres: may mydb ::1(59842) idle

当我观察到很少有进程处于空闲状态并且事务和我的数据库查询超时时,我检查了哪个表正在获取锁。

SELECT relation, pid, mode, granted, relname
FROM pg_locks
INNER JOIN pg_stat_user_tables
ON pg_locks.relation = pg_stat_user_tables.relid
WHERE pg_locks.pid='30476';

relation    pid    mode            granted   relname
16553      30476  AccessShareLock   TRUE    scheduler_task

请帮助我,我已经彻底检查了我的调度程序代码,并且在每次事务之后都会调用 db.commit()。

版本:

Version
2.17.2-stable+timestamp.2018.10.06.18.54.02
(Running on nginx/1.10.3, Python 2.7.12)

web2py is up to date
4

1 回答 1

0

您的应用程序真的按照服务启动配置的方式称为“myApp”ExecStart=/usr/bin/python /home/www-data/web2py/web2py.py -K myApp吗?

您必须按名称指定您的应用程序。'myapp' 只是一个占位符。

最好的问候克莱门斯

于 2018-10-25T21:54:20.953 回答