Comments (4)
@yuest 能给一段最简单的示例代码吗?我贴到readme里面去。
from pm.
var app = require('express').createServer()
app.get('/error', function(req, res, next) {
next(new Error('error'))
})
app.error(function(err, req, res) {
res.statusCode = 500
res.end(err.message)
})
//app.listen(8080) //没问题
//使用 node-cluster 有问题
//因为 app 没有触发 listening
//可以在此加一句
//app.emit('listening')
var worker = require('node-cluster').Worker()
worker.ready(function(socket) {
app.emit('connection', socket)
})
不过推荐不使用 app.error,而用 app.use(function(err, req, res, next) {}) 四个参数的 middleware
express 3.0 会去掉 app.error
from pm.
又想了一下,建议是不是加一个 worker.listen()
在 worker 里面 (new require('node-cluster').Worker).listen(app) 这样,可以简化为 cluster.listen(app)
因为现在的调用方式直接传递 socket,封装一下让 node-cluster 库来做这个事情,将来 node 有升级的话也能从 node-cluster 库这边来跟进。
from pm.
之前考虑过这种方式,每个worker遵从固定的interface去实现逻辑,与socket的交互完全由node-cluster去做。但这种方法要做到通用化的解决方案势必把这个interface搞得很复杂,还没完全想清楚怎么做。yuest有思路可以提一个pull过来吗?
from pm.
Related Issues (20)
- exception throw out for heartbeat when got sigterm
- need to fixed test case fails.
- worker is killed as soon as forked
- 能否支持worker在不同的机器上跑? HOT 6
- master crash with "uv__write: Assertion `fd_to_send >= 0' failed" HOT 4
- 执行Worker.reload()时,若某个worker进程还有没处理完的请求,能否等其处理完再退出? HOT 5
- work直接监听模式 HOT 3
- 请问这个跟Node官方的Cluster之间有什么区别? HOT 4
- pm 怎么搭配 express来使用 HOT 1
- 我在 worker.js 里 console.log('ooxx'),在浏览器刷新页面会出现2~5条的ooxx,什么情况? HOT 13
- Support Cluster.Worker API HOT 4
- aaa HOT 2
- 你好,请教你几个问题哈 HOT 2
- 关于集成pm与kraken HOT 4
- 当我control+c 终止master进程的时候,报错 HOT 1
- 怎样杀死所有子进程? HOT 1
- PM监听端口有没有个数限制? HOT 1
- 你好,请教关于监听地址的问题 HOT 1
- 0 down time 更新问题
- windows环境下tcp_wrap报错,Linux环境未测试
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pm.