Skip to content
Merged

fix #64

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module.exports = {
name: "comeet",
script: "dist/main.js",
watch: false,
instances: 3,
exec_mode: "cluster",
instances: 1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Switching from cluster mode with 3 instances to fork mode with a single instance will significantly impact the application's performance and scalability, as it will no longer be able to utilize multiple CPU cores for handling requests. This also reduces availability as there is no longer any redundancy.

If this change is intended to resolve issues with scheduled tasks (@nestjs/schedule) running on multiple instances, which is a common problem with cluster mode, please consider alternative solutions that don't sacrifice scalability:

  • Use a distributed lock: Implement a locking mechanism (e.g., using Redis or a database) to ensure that a scheduled task is executed by only one instance at a time.
  • Designate a worker instance: You could have a separate PM2 app definition for a single worker instance that is responsible for running scheduled tasks, while the main app continues to run in cluster mode for handling API requests. For example:
    // ecosystem.config.js
    module.exports = {
      apps: [
        {
          name: "comeet-api",
          script: "dist/main.js",
          instances: -1, // Use all available CPUs
          exec_mode: "cluster",
          env: {
            IS_WORKER: "false"
          }
        },
        {
          name: "comeet-worker",
          script: "dist/main.js",
          instances: 1,
          exec_mode: "fork", // Explicitly fork mode for worker
          env: {
            IS_WORKER: "true"
          }
        }
      ]
    };
    In your application code, you would then conditionally register the ScheduleModule based on the IS_WORKER environment variable.

If this change is made for other reasons, it's highly recommended to add a comment to the configuration file explaining the rationale for running in single-instance fork mode to aid future maintenance.

max_memory_restart: "256M",
output: "/dev/stdout",
error: "/dev/stderr",
Expand Down