Skip to content

REST API policy creation/deletion operations take an extremely long time to process as number of policies increases #7715

@AlejandroFrndz

Description

@AlejandroFrndz

Short description

We have OPA running as an independent pod in Kubernetes (no sidecar) with the following config:

OPA version: 1.0.0
Command:
run --server --log-level=debug --config-file=/policies/opa_config.yaml --set=default_decision=/main/decision --addr=0.0.0.0:8181 /policies
OPA config:

services:
  app-namel:
    url: ${API_URL}/v1
    response_header_timeout_seconds: 5
    credentials:
      bearer:
        token: ${OPA_API_KEY}

We then proceed to load our suite of around 4000 policies, with an average of 3 to 5 rules in each policy. During this process we noticed the time it takes for a new policy to be added increases as the number of policies already created grows. While this could be expected, we're reaching an unreasonable processing time fairly quickly. With around 1500 policies created we're experiencing processing times of around 6 seconds for each policy creation (PUT) operation. We've topped the issue at over 12 seconds when all the 4000 policies are loaded.

For the loading process, we've tried both loading policies from disk (with a mounted volume in Kubernetes) and loading via API but the end result is the same. When loading from disk, after all policies are loaded API operations take extremely long. When loading via API, each operation takes increasingly longer as described above the more policies already exist

We've also experienced and unusually high memory usage, which spikes up even further when creating new policies. According to Resource Utilization and considering we're loading around 20k rules, we should be seeing a memory usage of 260MB give or take. Instead, we're sitting at around 500MB which spikes up to 1GB while processing policy creation. We're not loading any external data in OPA (we provide input data at evaluation time along with the policy querying)

Steps To Reproduce

  1. Deploy OPA service
  2. Load at least between 3-5k rules into OPA (in our case bundled in around 1.5k policies)
  3. Attempt to create, update or delete policies via the REST API and monitor how long those API operations work

Expected behavior

API operations, while they might take a bit longer as more policies are loaded, should be kept at reasonable processing times.
Memory consumption should not be as high and shouldn't double during policy creation

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions