Skip to content
CCPEDIAby Unity Nodes
App Development

Reducing JSON API's memory usage

2 posts247 viewsLast activity Sep 2023

  1. Chan_LeeOP

    Hi all,

    Is there a way to reduce the memory footprint of the JSON API?

    Our dev environment has a three participant setup using a single Canton container and three JSON APi containers and the memory required is becoming too burdensome. Canton takes about ~2.5 GBs which is fine but each of the JSON API containers takes ~1.5 GBs which leaves very little room for the rest of our stack.

    We’ve been working around this by bumping Docker memory allocation from 8 GBs to10 GBs but that’s steadily becoming insufficient as we continue development.

    Is there anything we can do to cut down on memory?

    The JSON API conf we’re using:

    {
      server {
        address = "0.0.0.0"
        port = ${HTTP_PORT}
      }
    
      ledger-api {
        address = ${LEDGER_HOST}
        port = ${LEDGER_PORT}
      }
    
      metrics {
        //Start a metrics reporter. Must be one of "console", "csv:///PATH", "graphite://HOST[:PORT][/METRIC_PREFIX]", or "prometheus://HOST[:PORT]".
        reporter = "console"
        //Set metric reporting interval , examples : 1s, 30s, 1m, 1h
        reporting-interval = 1h
      }
    }
    

    The Dockerfile

    FROM amazoncorretto:19.0.2 as base
    
    FROM base as build
    
    RUN mkdir /jars && curl -L -o /jars/http-json.jar https://github.com/digital-asset/daml/releases/download/v2.5.5/http-json-2.5.5.jar
    
    FROM base as release
    
    RUN yum upgrade -y \
        && yum install -y shadow-utils gettext \
        && yum clean all \
        && groupadd --gid 1002 --system app \
        && useradd --uid 1001 --gid app --system app
    
    RUN mkdir /app && chown app:app /app
    
    USER app
    
    COPY --chown=app:app --from=build /jars /app/jars
    COPY --chown=app:app ./json-api-app.conf /app/json-api-app.conf
    COPY --chown=app:app ./docker-entrypoint.sh /
    
    
    ENV LEDGER_HOST localhost
    ENV LEDGER_PORT 6865
    ENV HTTP_PORT 7575
    ENV DB_SCHEMA_NAME postgres
    ENV LOG_LEVEL INFO
    
    ENTRYPOINT ["sh", "docker-entrypoint.sh"]
    

    Entrypoint

    #!/bin/sh
    cat /app/json-api-app.conf | envsubst > /app/json-api-app.with-env.conf
    
    echo "Using config file: "
    cat /app/json-api-app.with-env.conf
    
    exec java \
      -jar /app/jars/http-json.jar \
      --config /app/json-api-app.with-env.conf \
      --log-level $LOG_LEVEL \
      --log-encoder json
    
  2. Chan_Lee

    Disregard - fixed this by consolidating HTTP JSON containers and participants.

    We “emulate” a three participant setup by making sure each participant has its own party. In deployed environments, we still use multiple containers.