You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// worker.jsconsthttp=require('node:http');const{ id }=require('node:worker_threads').workerData;const{ createReuseportFd }=require('node-unix-socket');constserver=http.createServer((req,res)=>{res.end(`id=${id}`);});constfd=createReuseportFd(8000,'127.0.0.1');server.listen({fd},()=>{console.log(`worker#${id} listening on 8000`);});
The text was updated successfully, but these errors were encountered:
请详细告知你的新点子(Nice Ideas):
背景
最近的 egg.js 终于支持了
worker_threads
模式,但是相较于process
模式,该模式在启动多个app_worker
时需要为每个app_worker
指定一个监听端口,这导致使用者必须配置 nginx 之类的前置代理,行为也和process
模式不一样。想法
Linux 3.9 后可以通过
SO_REUSEPORT
选项让多个进程或线程监听同一个端口,并且自动负载均衡;因此,可以考虑:SO_REUSEPORT
实现类似process
模式的效果。示例代码
这里通过字节的
node-unix-socket
模块创建一个SO_REUSEPORT
的fd
:The text was updated successfully, but these errors were encountered: