Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update with max_memory_restart

...

  1. First, is by adding the "exec_mode" and "instances" settings to your JSON configuration as follows.  The "exec_mode" setting enables cluster mode, while the "instances" setting allows you to customize how many CPUs are available to PM2 ("max" = all CPUs, but you also can specify a number.You also may want to set the "max_memory_restart" option to avoid PM2 using too much memory.  These three settings are described in more detail below.  NOTE: make sure to start (or restart) your site to enable these settings (e.g. pm2 start dspace-ui.json)

    Code Block
    languagejs
    titledspace-ui.json
    {
        "apps": [
            {
               "name": "dspace-ui",
               "cwd": "/full/path/to/dspace-ui-deploy",
               "script": "dist/server/main.js",
               "instances": "max",
               "exec_mode": "cluster",
               "env": {
                  "NODE_ENV": "production"
               },
                }
    "max_memory_restart": "500M"
          ]
    }

    Then, start (or restart) your site as normal (e.g. pm2 start dspace-ui.json)

      }
        ]
    }


    1. Setting "exec_mode" to "cluster" will enable cluster mode,

    2. The "instances" setting allows you to customize how many CPUs are available to PM2 ("max" = all CPUs. But you also can specify a number like "8" = 8 CPUs. )
    3. The "max_memory_restart" setting is optional but tells PM2 how much memory to allow per instance.  The example above has a maximum of 500MB.  If the number of 'instances' is 8, that would mean PM2 could use up to 8 x 500MB = 4GB of memory.  Therefore, you may wish to modify the values of "instances" and/or "max_memory_restart" to better control the memory available to PM2.
  2. Alternatively, you can use command line flags to specify the same settings described above.  The "-i" flag enables cluster mode and specifies the number of instances.  The "--max-memory-restart" flag limits the memory per instance.

    Code Block
    # Start the "dspace-ui" app. Cluster it across all available CPUs with a maximum memory of 500MB per CPU.
    # This command is equivalent to the example cluster settings in the "dspace-ui.json" file above.

    Alternatively, you can pass in the "-i" flag with either "max" or a number to tell PM2 to run in cluster mode across that many CPUs:

    Code Block
    # Start the "dspace-ui" app & cluster it across all available CPUs
    pm2 start dspace-ui.json -i max --max-memory-restart 500M


Give Node.js more memory

On machines with >2GB of memory available, Node will only use a maximum of 2GB of memory by default (see https://github.com/nodejs/node/issues/28202).  This 2GB of memory should be enough to build & run the User Interface, but it's possible that highly active sites may require 4GB or more.

...