Clustering not working with Bun
What's going wrong?
Clustering do not work with Bun. 😕
How could we reproduce this issue?
The following spawns forked instead of cluster:
pm2 start --interpreter /opt/homebrew/bin/bun --instances 2 ./build/index.js
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Wed Sep 18 2024 14:47:12 GMT+0530 (India Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.4.2
node version : 20.17.0
node path : /Users/harry/.bun/bin/pm2
argv : /opt/homebrew/Cellar/node@20/20.17.0/bin/node,/Users/harry/.bun/install/global/node_modules/pm2/lib/Daemon.js
argv0 : node
user : harry
uid : 501
gid : 20
uptime : 7min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.4.2
node version : 20.17.0
node path : /Users/harry/.bun/bin/pm2
argv : /opt/homebrew/Cellar/node@20/20.17.0/bin/node,/Users/harry/.bun/bin/pm2,report
argv0 : node
user : harry
uid : 501
gid : 20
===============================================================================
--- System info --------------------------------------------
arch : arm64
platform : darwin
type : Darwin
cpus : Apple M2
cpus nb : 8
freemem : 313901056
totalmem : 17179869184
home : /Users/harry
@harryqt try doing bun --bun run pm2 start --...
bun --bun run pm2 start --instances 2 ./build/index.js
i checked pm2.log and found this. is this related @Jarred-Sumner ?
Me the same
is this related
I don't think pm2 uses node:inspector
@harryqt Hi Bro, do you find any workaround?
Nope. Had to revert back to Nodejs. ☹️
Nope. Had to revert back to Nodejs. ☹️
Too bad I would actually like to save myself that but if there is no other solution you have to switch back to NodeJs 😢
Try to install bun using npm npm install -g bun, this worked for me.
Try to install bun using npm
npm install -g bun, this worked for me.
Unfortunately, I don't have the opportunity to test it at the moment. Has anyone else tried it and can confirm this?
Try to install bun using npm
npm install -g bun, this worked for me.Unfortunately, I don't have the opportunity to test it at the moment. Has anyone else tried it and can confirm this?
@deanrather That won't work. @Al0olo thinks it works because pm2 will use node instead of bun under the hood.
@harryqt Actually in my case it was using ts-node instead of bun, so I assumed it's doing this by default.
Hi all, I find a workaround. https://github.com/mario-huang/web-frameworks/blob/master/javascript/durian.js/cluster.ts
bun run cluster.ts
@mario-huang the link seems to take to a blank page.
@sindelio Corrected: https://github.com/mario-huang/web-frameworks/blob/master/javascript/durian.js/cluster.ts
@mario-huang https://nodejs.org/api/os.html#oscpus:~:text=os.cpus().length%20should%20not%20be%20used%20to%20calculate%20the%20amount%20of%20parallelism%20available%20to%20an%20application.%20Use%20os.availableParallelism()%20for%20this%20purpose
@mario-huang the link seems to take to a blank page.
sorry, fixed
@sindelio Corrected: https://github.com/mario-huang/web-frameworks/blob/master/javascript/durian.js/cluster.ts
@mario-huang https://nodejs.org/api/os.html#oscpus:~:text=os.cpus().length%20should%20not%20be%20used%20to%20calculate%20the%20amount%20of%20parallelism%20available%20to%20an%20application.%20Use%20os.availableParallelism()%20for%20this%20purpose
That's better, thanks.
Before I do the work and finally switch back from bun to node js, I wanted to ask the community again... what do you think... will bun run out of the box with pm2 in cluster mode in the foreseeable future? I have the feeling that neither @Jarred-Sumner and @Unitech have much interest in this at the moment. What do you think?
Will do
@Unitech Will do
This is good news for many in the bun community. I hope that the compatibility will be integrated in one of the next releases very soon?
Will do
@Unitech can you already estimate when you will integrate compatibility from Bun? Will it perhaps be in the next release?
Will do
@Unitech can you already estimate when you will integrate compatibility from Bun? Will it perhaps be in the next release?
https://github.com/Unitech/pm2/tree/development
Will do
@Unitech can you already estimate when you will integrate compatibility from Bun? Will it perhaps be in the next release?
https://github.com/Unitech/pm2/tree/development
Oh... I hadn't even seen that. Thank you very much!
Work in progress : https://github.com/Unitech/pm2/commit/d9e6964f46a9666d7ebad20aac42cbda25e93faf
Full Bun support is available in beta, please could you try it and report me any bugs:
bun install pm2-beta -g
pm2 update
Thanks
what's the plan on releasing
Apparently this release will never be released
Apparently this release will never be released
Maybe because the community does not support testing!?
Let me know when you've tried it and confirmed that it works as expected, then I will make a release