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
I created this discussion to provide updates about how to run an AceBase server in a pm2, cloud or standard Node.js cluster.
Cloud based (multiple machine) clusters
If you want to run an AceBase server in a cloud-based cluster, where multiple machines are accessing the same data files, you have to use an external IPC server: https://github.com/appy-one/acebase-ipc-server
pm2 / Node.js clusters
If you want to use pm2 to vertically scale the processes running on a single machine, or want to be able to access the same database files from multiple isolated processed, enable the new socket IPC mode (requires acebase-server v1.18.0+). This will automatically spawn a single master process for the database (if it's not running yet), and connects to it using a Unix socket or Windows named pipe.
Simply pass ipc: 'socket' in your config to enable this and it'll work!
Before the socket IPC mode was introduced, you had to (and still can) use the manual IPC configuration using master and worker roles. It's best not to use this approach anymore, but I'll include put the example code taken from cluster.ts here for future reference:
import{AceBase}from'acebase';import{AceBaseServer,AceBaseServerSettings}from'acebase-server';import*asclusterfrom'cluster';import*asosfrom'os';constnumCPUs=os.cpus().length;constdbname='default';constoptions: AceBaseServerSettings={/* default options */};options.authentication={enabled: false};options.https={enabled: false};if(cluster.isMaster){// Startup masterconsole.log(`Starting database server cluster with ${numCPUs} workers`);constmaster=newAceBase(dbname,options);master.once('ready',()=>{console.log(`Master database server started on process ${process.pid}`);});for(leti=0;i<numCPUs;i++){constworker=cluster.fork();}cluster.on('exit',(worker,code,signal)=>{console.error(`worker ${worker.process.pid} died`);cluster.fork();// restart});}else{console.log(`Worker ${process.pid} is running`);constserver=newAceBaseServer(dbname,options);server.ready(()=>{console.log(`Worker database server started on process ${process.pid}`);});}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Clustering info
I created this discussion to provide updates about how to run an AceBase server in a pm2, cloud or standard Node.js cluster.
Cloud based (multiple machine) clusters
If you want to run an AceBase server in a cloud-based cluster, where multiple machines are accessing the same data files, you have to use an external IPC server: https://github.com/appy-one/acebase-ipc-server
pm2 / Node.js clusters
If you want to use pm2 to vertically scale the processes running on a single machine, or want to be able to access the same database files from multiple isolated processed, enable the new
socket
IPC mode (requires acebase-server v1.18.0+). This will automatically spawn a single master process for the database (if it's not running yet), and connects to it using a Unix socket or Windows named pipe.Simply pass
ipc: 'socket'
in your config to enable this and it'll work!That's it!
Manual Node.js cluster plumbing
Before the socket IPC mode was introduced, you had to (and still can) use the manual IPC configuration using
master
andworker
roles. It's best not to use this approach anymore, but I'll include put the example code taken fromcluster.ts
here for future reference:Beta Was this translation helpful? Give feedback.
All reactions