多进程下process.pid每次打印都相同的问题
What happens?
在单机多进程部署下, 通过this.app.uid="ABCD";
controller中, 打印process.pid 和 app.uid 为何每次都和上一次打印的一样? 不应该是按照进程随机的吗?
用 curl 试,浏览器有 keep alive
试了curl, 结果还是一样的
Hello @P3T3R-Z. Please provide a reproducible example following the instruction.
Issues labeled by Need Reproduce will be closed if no activities in 7 days.
@P3T3R-Z,请根据这个说明提供最小可复现代码。
如果在 7 天内没有进展会被自动关闭。
schedule/test.js ctx.app赋值ABCD
module.exports = {
schedule: {
interval: "10s",
type: "worker",
disable: false,
immediate: true,
},
async task(ctx) {
ctx.app.uid='ABCD'
console.log('from schedule====>', ctx.app.uid, process.pid)
},
};
controller/test.js controller中打印app对象的uid
...
async index(){
console.log('from controller--------->', this.ctx.app.uid, process.pid)
}
采用curl方式, 打印结果如下
from controller---------> undefined 18256
from schedule====> ABCD 6572
from controller---------> undefined 18256
from controller---------> undefined 18256
from controller---------> undefined 18256
from schedule====> ABCD 18256
from controller---------> ABCD 18256
from controller---------> ABCD 18256
from controller---------> ABCD 18256
请按上面的提示,提交最小可复现仓库。
你是本地 dev 测试?
本地测试, 加了-c参数
egg-bin dev --port=8080 --sticky -c=4
可能我描述的不太准确, 应该是每次打印的process.pid都是一样的
你加了 --sticky 的原因
https://github.com/eggjs/egg-cluster/blob/63c3cd0dcbd5d3ca8d6b6c5bf08c85f4dd698d25/lib/master.js#L218