IBM Cloud Docs
Why aren't my app instances scaling down as expected?

Why aren't my app instances scaling down as expected?

When traffic to your application slows down such that your app begins to scale down, you observe that instances do not go away.

When the incoming workload is slows to your application, Code Engine starts to automatically scale down an application based on its configured scaling values. Code Engine sends a SIGTERM message to your application. Your code must react to this signal and shut down. If your code does not do handle the SIGTERM message, your application instances remain in Terminating status during the configured request time out value (default: 300 seconds).

Try one of these solutions.

  • Review the documentation about how scaling works. See Configuring application scaling.

  • Review the values configured for autoscaling for your application.

    • From the console, go to the page for your application. The autoscaling settings are on the Configuration > Runtime tab.
    • With the CLI, run the ibmcloud ce app get command to display details of your app.
  • Ensure that your code handles SIGTERM messages. For applications to scale down cleanly, your application code must handle a SIGTERM signal. When Code Engine automatically scales down, a SIGTERM signal is sent to your application.

    The following code example handles a SIGTERM message because it closes the connection to the HTTP server that was started by the app after the app receives a signal that the instance ends.

    const server = // start the HTTP server
    
    process.on('SIGTERM', () => {
      console.info('SIGTERM signal received.');
      server.close(() => {
        console.log('Http server closed.');
      });
    });
    
  • Review the details of your app instances to help you troubleshoot your app. See Getting details about app instances.