Updated on 2023-11-21 GMT+08:00

Configuring Heartbeat Function

Introduction

A heartbeat function detects the following exceptions of your functions:
  • Deadlock
  • Memory overflow
  • Network errors

After you configure a heartbeat function, FunctionGraph sends a heartbeat request to your function instance every 5s. If the response is abnormal, FunctionGraph terminates the function instance.

The heartbeat request timeout is 3s. If no response is returned for six consecutive times, the function instance will be stopped.

Constraints

  1. Heartbeat detection is available for Java functions.
  2. The heartbeat function entry must be in the same file as your function handler.

    Java heartbeat function format:

    public boolean heartbeat() {
    	// Custom detection logic
    	return true
  3. The heartbeat function has no input parameter and its return value is Boolean.

Procedure

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click the function to be configured to go to the function details page.
  3. Click the Configuration tab and choose Advanced Settings.
  4. Enable Heartbeat Function and set the function entry.

    Figure 1 Configuring a heartbeat function
    Table 1 Heartbeat function configuration

    Parameter

    Description

    Heartbeat Function

    If this option is enabled, FunctionGraph detects exceptions when your function is running.

    Heartbeat Function Entry

    The heartbeat function entry must be in the same file as your function handler.

    The value can contain a maximum of 128 characters in the format of "[package name].[class name].[execution function name]".

  5. Click Save.