- MeritRank
- How to Launch the Project with Docker
- Manual Launch Instructions
After a service restart, loading many edges one-by-one with mr_put_edge can be slow. Use batch loading to send all edges in a single request:
- SQL:
mr_bulk_load_edges(src_arr, dst_arr, weight_arr, magnitude_arr, context_arr, timeout_msec)— see PSQL Connector. - The service clears existing walks, loads the edges without computing walks, and blocks other requests until the load finishes. Walks are created lazily on first score/graph/neighbor reads per ego.
Ops queue and processing-time stats are off by default. To enable them (e.g. for load testing or tuning), set MERITRANK_COLLECT_STATS=true. Then use ResetStats and GetStats via the protocol; see Service env vars.
To install Docker on a Debian-based system, follow the steps provided on Docker's official site.
If you'd like a shortcut that prepares everything in a single command, use the following:
sudo apt install docker.io git && \
git clone https://github.com/Intersubjective/meritrank-rust.git && \
cd meritrank-rust && \
docker build -t mr-service -f service/Dockerfile . && \
docker build -t mr-psql-connector -f psql-connector/Dockerfile . && \
docker network create my-network && \
docker run --network my-network -p 10234:10234 -e MERITRANK_SERVICE_URL=tcp://0.0.0.0:10234 --detach --name container1 mr-service && \
docker run --network my-network -e POSTGRES_PASSWORD=postgres -e MERITRANK_SERVICE_URL=tcp://container1:10234 --detach --name container2 -p 5432:5432 mr-psql-connector:latestEnsure you have git and docker installed before running these commands. We’ll build both the service and the psql-connector.
git clone https://github.com/Intersubjective/meritrank-rust.git
cd meritrank-rust
docker build -t mr-service -f service/Dockerfile .docker build -t mr-psql-connector -f psql-connector/Dockerfile .Creating a shared network is necessary for smooth communication between mr-service and mr-psql-connector. By setting up a custom network (my-network), the containers can communicate directly by container name, simplifying the connection setup specified in MERITRANK_SERVICE_URL.
docker network create my-networkUse this command to launch mr-service:
docker run --network my-network -p 10234:10234 -e MERITRANK_SERVICE_URL=tcp://0.0.0.0:10234 --name container1 mr-service--network my-network: Connectsmr-serviceto the shared network.-p 10234:10234: Exposes the service on port 10234 for external access.- The
tcp://0.0.0.0address configures the service to listen on all network interfaces, enabling connections to port 10234 from any reachable IP.
Then, run this command to start mr-psql-connector:
docker run --network my-network -e POSTGRES_PASSWORD=postgres -e MERITRANK_SERVICE_URL=tcp://container1:10234 --name container2 -p 5432:5432 mr-psql-connector:latest--network my-network: Connectsmr-psql-connectorto the shared network.-e POSTGRES_PASSWORD=postgres: Sets a password for the default PostgreSQL user (required to avoid errors).- The
MERITRANK_SERVICE_URL=tcp://container1:10234connection string links tomr-serviceat port 10234. --name container2: Names the containercontainer2.-p 5432:5432: Exposes PostgreSQL on port 5432 for external access.
You can open an interactive shell session inside container2 as the PostgreSQL user to manage your database.
docker exec -it container2 su - postgres && psqlHere are some basic commands to try:
\df
SELECT mr_service_url();
SELECT mr_service();
SELECT mr_create_context('my-context'); If you’d prefer to install everything with a single command that also verifies Rust’s installation on your system, use the following:
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-config rustc clang git cmake && \
if command -v rustc &> /dev/null; then echo "Rust is already installed"; else curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh && source "$HOME/.cargo/env"; fi && \
git clone https://github.com/Intersubjective/meritrank-rust.gitTo start the service, from the repo root run:
cd meritrank-rust && cargo run -p meritrank_service > log.txt 2>&1Or from the service directory: cd meritrank-rust/service && cargo run > log.txt 2>&1
Proceed to the psql-connector directory, initialize, and start pgrx:
cd ../psql-connector
cargo install --locked cargo-pgrx
cargo pgrx init
cargo pgrx runBefore launching the project, ensure all necessary dependencies are installed. For Debian-based distributions, use the following commands:
sudo apt-get install build-essential libreadline-dev zlib1g-dev flex bison libxml2-dev libxslt-dev libssl-dev libxml2-utils xsltproc ccache pkg-configsudo apt-get install rustc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install rustup
source "$HOME/.cargo/env" # Add Rust to PATHsudo apt-get install clang gitTo start meritrank-service-rust, from the repo root use:
cd meritrank-rust
cargo run -p meritrank_serviceNavigate to the psql-connector directory:
cd meritrank-rust/psql-connectorSome steps for setting up pgrx are covered on the pgrx GitHub page.
cargo install --locked cargo-pgrx This command will download, compile supported PostgreSQL versions into ${PGRX_HOME}, and run initdb:
cargo pgrx initTo run automated tests:
export RUST_TEST_THREADS=1
cargo pgrx testIf tests pass without errors, you can launch the service with:
cargo pgrx runTo access psql and interact with MeritRank’s service via the psql connector, log in as the postgres user and open psql:
su - postgres
psqlYou can now execute the following commands to verify that the service is running correctly:
\df
SELECT mr_service_url();
SELECT mr_service();
SELECT mr_create_context('my-context');