20.1.3.1.1 Configuring On-Heap Limits

The on-heap memory limits for the graph server (PGX) can be configured by updating the systemd configuration file for the PGX service. However, there is a risk of losing the updates to the configuration file, the next time you upgrade the graph server (PGX). Therefore, it is recommended that you provide the on-heap memory configuration in a drop-in file. All directives in the drop-in file are dynamically merged with the directives in the main configuration file (/etc/systemd/system/pgx.service) during the graph server (PGX) startup.

You can perform the following steps to create a drop-in file and configure the on-heap memory size:

  1. Navigate to the /etc/systemd/system/pgx.service.d directory. If the pgx.service.d directory does not exist in the file path, then create one.
  2. Create a drop-in file (.conf file) with any name in /etc/systemd/system/pgx.service.d. Skip this step, if one already exists.
  3. Edit the drop-in file as a root user or with sudo command and add the on-heap memory option in the [Service] section as shown:
    sudo vi /etc/systemd/system/pgx.service.d/setup.conf

    The following example displays the added on-heap memory setting in the setup.conf file:

    [Service]
    # Java on-heap memory setting
    Environment="JAVA_TOOL_OPTIONS=-Xms1G -Xmx2G"

    This option sets the initial heap space to 1GB and allows it to grow up to 2GB.

    The supported options for configuring the on-heap memory are:

    • -Xmx: to set the maximum on-heap size of the JVM.
    • -Xms: to set the initial on-heap size of the JVM.
    • -XX:NewSize: to set the initial size of the young generation
    • -XX:MaxNewSize: to set the maximum size of the young generation

    See the java command documentation for more information on these options.

  4. Add the JAVA_HOME environment variable to ensure that the graph server (PGX) is using the appropriate JDK.
    [Service]
    # JAVA_HOME variable
    Environment=JAVA_HOME=/usr/java/jdk-15.0.1/
    # Java on-heap memory setting
    Environment="JAVA_TOOL_OPTIONS=-Xms1G -Xmx2G"

    Note that the comments begin with # and you can optionally comment any specific option in order to test your configuration.

  5. Reload the PGX service to use the updated settings by running the following command:

    sudo systemctl daemon-reload

  6. Restart the graph server (PGX):

    sudo systemctl restart pgx

  7. Verify that the new memory setting is correctly passed to the graph server (PGX):
    sudo systemctl show pgx -p Environment
    Environment=PGX_SERVER_KEYSTORE_PASSWORD=changeit JAVA_HOME=/usr/java/jdk-15.0.1/ JAVA_TOOL_OPTIONS=-Xms1G\x20-Xmx2G
  8. Verify that the new memory setting is used by the graph server (PGX):
    $ sudo journalctl -u pgx -n 50 | grep JAVA_TOOL_OPTIONS
    Sep 26 10:52:46 localvm.localdomain bash[25206]: Picked up JAVA_TOOL_OPTIONS: -Xms1G -Xmx2G
  9. Finally, use the server-state REST endpoint to confirm the new memory usage. For example:
    $ BASE_URL=https://localhost:7007
    $ USERNAME=graph
    $ PASSWORD=graph
    $ PGX_RESPONSE=`curl -s -k -X POST -H 'Content-Type: application/json' -d '{"username": "'"${USERNAME}"'", "password": "'"${PASSWORD}"'"}' ${BASE_URL}/auth/token`
    $ PGX_ACCESS_TOKEN=`echo $PGX_RESPONSE | jq -r '.access_token'`
    $ echo `curl -s -k -H 'Authorization: Bearer '"${PGX_ACCESS_TOKEN}" $BASE_URL/control/v1/serverState|jq '.entity.memory'` |jq
    {
      "localvm.localdomain": [
        {
          "free_heap_mb": 830,
          "current_heap_mb": 989,
          "used_heap_mb": 159,
          "maximum_heap_mb": 1979,
          "type": "java_heap"
        },
        {
          "used_off_heap_mb": 0,
          "maximum_off_heap_mb": 1741,
          "current_off_heap_mb": 1741,
          "free_off_heap_mb": 1741,
          "type": "unmanaged"
        }
      ]
    }