16.2.1.2 Progress Reporting and Estimation for Graph Loading
Loading a large graph into the graph server(PGX) can be a long running operation. However, if you load the graph using an asynchronous action, then you can monitor the progress of the graph loading operation.
The following table shows the asynchronous graph loading APIs supported for the following formats:
Table 16-3 Asynchronous Graph Loading APIs
Data Format | API |
---|---|
PGQL Property Graph | session.readGraphByNameAsync() |
PG SCHEMA | session.readGraphWithPropertiesAsync() |
CSV | session.readGraphFileAsync() |
These supported APIs return a PgxFuture
object.
You can then use the PgxFuture.getProgress()
method to collect the
following statistics:
- Report on the progress of the graph loading operation
- Estimate of the remaining vertices and edges that need to be loaded into memory
For example, the following code shows the steps to load a PGQL property graph graph asynchronously and
subsequently obtain the FutureProgress
object to report and estimate
the loading progress. However, note that the graph loading estimate (for example, the
number of loaded entities and providers or the number of total entities and providers)
can be obtained only until the graph loading operation is in progress. Also, the system
internally computes the graph loading progress for every 10000 entries of entities that
are loaded into the graph server (PGX).
opg4j> var graphLoadingFuture = session.readGraphByNameAsync("BANK_GRAPH_VIEW", GraphSource.PG_VIEW)
readGraphFuture ==> oracle.pgx.api.PgxFuture@6106dfb6[Not completed]
opg4j> while (!graphLoadingFuture.isDone()) {
...> var progress = graphLoadingFuture.getProgress();
...> var graphLoadingProgress = progress.asGraphLoadingProgress();
...> if (graphLoadingProgress.isPresent()) {
...> var numLoadedVertices = graphLoadingProgress.get().getNumLoadedVertices();
...> }
...> Thread.sleep(1000);
...> }
opg4j> var graph = graphLoadingFuture.get();
graph ==> PgxGraph[name=BANK_GRAPH_VIEW_3,N=999,E=4993,created=1664289985985]
PgxFuture<PgxGraph> graphLoadingFuture = session.readGraphByNameAsync("BANK_GRAPH_VIEW", GraphSource.PG_VIEW);
while (!graphLoadingFuture.isDone()) {
FutureProgress progress = graphLoadingFuture.getProgress();
Optional < GraphLoadingProgress > graphLoadingProgress = progress.asGraphLoadingProgress();
if (graphLoadingProgress.isPresent()) {
long numLoadedVertices = graphLoadingProgress.get().getNumLoadedVertices();
}
Thread.sleep(1000);
}
PgxGraph graph = graphLoadingFuture.get();
It is recommended that you do not use the FutureProgress
object in a
chain of asynchronous operations.