pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Clustering not working with Bun

Open harryqt opened this issue 1 year ago • 50 comments

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
Screenshot 2024-09-18 at 7 50 31 PM

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 avatar Sep 18 '24 09:09 harryqt

@harryqt try doing bun --bun run pm2 start --...

Jarred-Sumner avatar Sep 18 '24 14:09 Jarred-Sumner

bun --bun run pm2 start --instances 2 ./build/index.js
Screenshot 2024-09-18 at 8 25 36 PM Screenshot 2024-09-18 at 8 27 42 PM

harryqt avatar Sep 18 '24 14:09 harryqt

i checked pm2.log and found this. is this related @Jarred-Sumner ? image

mushonnip avatar Sep 19 '24 02:09 mushonnip

Me the same

mario-huang avatar Sep 19 '24 06:09 mario-huang

is this related

I don't think pm2 uses node:inspector

harryqt avatar Sep 19 '24 08:09 harryqt

@harryqt Hi Bro, do you find any workaround?

mario-huang avatar Sep 21 '24 05:09 mario-huang

Nope. Had to revert back to Nodejs. ☹️

harryqt avatar Sep 21 '24 07:09 harryqt

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 😢

dienstbereit avatar Sep 21 '24 10:09 dienstbereit

image

mario-huang avatar Sep 21 '24 12:09 mario-huang

Try to install bun using npm npm install -g bun, this worked for me.

Al0olo avatar Sep 24 '24 04:09 Al0olo

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?

dienstbereit avatar Sep 25 '24 09:09 dienstbereit

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 avatar Sep 25 '24 10:09 harryqt

@harryqt Actually in my case it was using ts-node instead of bun, so I assumed it's doing this by default.

Al0olo avatar Sep 25 '24 10:09 Al0olo

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 avatar Oct 05 '24 11:10 mario-huang

@mario-huang the link seems to take to a blank page.

sindelio avatar Oct 05 '24 16:10 sindelio

@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

harryqt avatar Oct 05 '24 16:10 harryqt

@mario-huang the link seems to take to a blank page.

sorry, fixed

mario-huang avatar Oct 06 '24 03:10 mario-huang

@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.

mario-huang avatar Oct 06 '24 03:10 mario-huang

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?

dienstbereit avatar Oct 08 '24 13:10 dienstbereit

Will do

Unitech avatar Oct 08 '24 20:10 Unitech

@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?

dienstbereit avatar Oct 14 '24 07:10 dienstbereit

Will do

@Unitech can you already estimate when you will integrate compatibility from Bun? Will it perhaps be in the next release?

dienstbereit avatar Nov 06 '24 15:11 dienstbereit

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

harryqt avatar Nov 06 '24 16:11 harryqt

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!

dienstbereit avatar Nov 06 '24 17:11 dienstbereit

Work in progress : https://github.com/Unitech/pm2/commit/d9e6964f46a9666d7ebad20aac42cbda25e93faf

Unitech avatar Nov 13 '24 12:11 Unitech

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

Unitech avatar Nov 15 '24 11:11 Unitech

what's the plan on releasing

boredjoker avatar Nov 27 '24 11:11 boredjoker

Apparently this release will never be released

kiyasov avatar Jan 11 '25 10:01 kiyasov

Apparently this release will never be released

Maybe because the community does not support testing!?

dienstbereit avatar Jan 11 '25 11:01 dienstbereit

Let me know when you've tried it and confirmed that it works as expected, then I will make a release

Unitech avatar Jan 13 '25 10:01 Unitech