PGX 21.1.1
Documentation

Preloading Graphs

The PGX engine can be configured to preload graphs in memory at startup-time. This can be useful for scenarios where you want PGX to startup automatically and have a graph (or multiple graphs) ready for its users. For example, deploying PGX on Kubernetes could be one such scenario.

The configuration for this is done through the preload_graphs configuration field in the PGX config.

A minimal example for preloading a graph using the graph config stored at graph-configs/my-graph.adj.json could look like this:

{ 
  "preload_graphs": [
    {
      "path": "graph-configs/my-graph.adj.json",
      "name": "my-graph"      
    }
  ]
}

A preloaded graph can be accessed by its name via the getGraph() method of the session object.

PgxGraph g = session.getGraph("my-graph");

Find details on how to specify graphs here. Refer to this page for more information on how to configure the PGX engine and runtime.

Publishing Preloaded Graphs

The publishing behavior for preloaded graphs can be controlled in the configuration. Unless a different behavior is configured, (only) the first loaded snapshot of a graph is published. Preloaded published graphs remain in memory even if they are not used by any session.

There are two options to control the publishing behavior:

  1. To publish only the graph but no future snapshots of the graph, set the optional flag publish to true. This is the default behavior; the default value of this flag is true.
  2. To publish the graph and all future snapshots of the graph, set the optional flag publish_with_snapshots to true. The default value is false.

Only one of these two flags can be set to true at the time. However, publishing the graph with snapshots does also publish the first version of the graph. Refer to Graph Publishing Guide for details on graph publishing.

Example

This example pgx.conf specifies two graphs for loading into memory during PGX startup-time. my-graph is published with snapshots while my-other-graph is published without snapshots.

{ 
  "enterprise_scheduler_config": {
    "analysis_task_config": {
      "max_threads": 32
    }
  },
  "preload_graphs": [
    {
      "path": "graph-configs/my-graph.bin.json",
      "name": "my-graph",
      "publish": false,
      "publish_with_snapshots": true
    },
    {
      "path": "graph-configs/my-other-graph.adj.json",
      "name": "my-other-graph"      
    }
  ]
}

The two preloaded graphs can be accessed as follows.

PgxGraph g1 = session.getGraph("my-graph");
PgxGraph g2 = session.getGraph("my-other-graph");

In the case of my-graph, getGraph() returns the most recent available snapshot.