Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(backend): cap ArangoDB's caches in the standalone compose (#856)

Ian Hock57955dfc7b02
diff --git a/docker-compose.standalone.yml b/docker-compose.standalone.yml
index 281ea4e2..70e753ad 100644
--- a/docker-compose.standalone.yml
+++ b/docker-compose.standalone.yml
@@ -30,7 +30,32 @@ services:
# before 3.12.11, which still accepts the old spelling but only as a renamed
# alias and warns. Pinning the image above is what makes it safe to state
# one spelling here.
- command: ["arangod", "--server.endpoint", "tcp://0.0.0.0:8529", "--vector-index", "true"]
+ #
+ # Cache caps. Left alone, arangod sizes its caches from the host's RAM (on
+ # a 30 GB machine: a ~9 GB block cache, not enforced by default, a ~7.6 GB
+ # edge/document cache and ~12 GB of write buffers), fills them, and keeps
+ # the memory after workspaces are dropped. The defaults below served repos
+ # up to ~30k files with no slowdown in `ix map`. They cap caches only, not
+ # the process: there is deliberately no container memory limit or query
+ # memory limit, which could kill the backend on a large repo.
+ # --rocksdb.block-cache-size 512 MB RocksDB block cache
+ # --rocksdb.enforce-block-cache-size-limit true hold it to that size
+ # --rocksdb.total-write-buffer-size 256 MB all memtables together
+ # --cache.size 128 MB edge/document cache
+ # To raise one, set its IX_ARANGO_* variable (bytes) in the .env next to
+ # this file, e.g. IX_ARANGO_BLOCK_CACHE_SIZE=2147483648, then run
+ # `ix docker stop` and `ix docker start` to recreate the container. The
+ # data volume is kept. See docs/prerequisites.md.
+ command:
+ - arangod
+ - --server.endpoint
+ - tcp://0.0.0.0:8529
+ - --vector-index
+ - "true"
+ - --rocksdb.block-cache-size=${IX_ARANGO_BLOCK_CACHE_SIZE:-536870912}
+ - --rocksdb.enforce-block-cache-size-limit=${IX_ARANGO_ENFORCE_BLOCK_CACHE_LIMIT:-true}
+ - --rocksdb.total-write-buffer-size=${IX_ARANGO_WRITE_BUFFER_SIZE:-268435456}
+ - --cache.size=${IX_ARANGO_CACHE_SIZE:-134217728}
volumes:
- arangodb-data:/var/lib/arangodb3
healthcheck:
diff --git a/docs/prerequisites.md b/docs/prerequisites.md
index f71747e3..d098c242 100644
--- a/docs/prerequisites.md
+++ b/docs/prerequisites.md
@@ -93,6 +93,21 @@ docker-compose>=2.0
# if you want its web UI: services: { arangodb: { ports: ["127.0.0.1:8529:8529"] } })
arangodb==3.12
+# Memory: ArangoDB would size its caches from the host's RAM (about 30% of
+# it), so the backend compose caps them instead. These are caches, not a
+# memory limit: a large repo is never killed for using more.
+# IX_ARANGO_BLOCK_CACHE_SIZE 536870912 (512 MB) RocksDB block cache
+# IX_ARANGO_ENFORCE_BLOCK_CACHE_LIMIT true hold it to that size
+# IX_ARANGO_WRITE_BUFFER_SIZE 268435456 (256 MB) RocksDB write buffers
+# IX_ARANGO_CACHE_SIZE 134217728 (128 MB) edge/document cache
+# To change one, set it (in bytes) in ~/.ix/backend/.env, next to the
+# compose file, e.g. IX_ARANGO_BLOCK_CACHE_SIZE=2147483648
+# It takes effect when the container is recreated: `ix docker stop` then
+# `ix docker start` (`ix docker restart` keeps the old settings). The data
+# volume is kept. An install whose ~/.ix/backend/docker-compose.yml predates
+# these settings keeps it until it is moved aside; `ix docker start` then
+# writes the one this CLI ships.
+
# Ix Memory Layer — Scala/JVM HTTP API (Docker container on 127.0.0.1:8090)
ix-memory-layer==latest
diff --git a/ix-cli/src/cli/__tests__/arangodb-cache-limits.test.ts b/ix-cli/src/cli/__tests__/arangodb-cache-limits.test.ts
new file mode 100644
index 00000000..b41edda8
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/arangodb-cache-limits.test.ts
@@ -0,0 +1,92 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { parse } from "yaml";
+import { backendEnvContents, writeBackendEnv } from "../backend-compose.js";
+
+/**
+ * ArangoDB sizes its caches from the host's RAM, so on a developer laptop the
+ * shipped backend held a large share of it for a small graph. The shipped
+ * compose file caps the caches (not the process), each cap overridable from
+ * ~/.ix/backend/.env.
+ */
+
+const REPO_COMPOSE = resolve(fileURLToPath(new URL("../../../../docker-compose.standalone.yml", import.meta.url)));
+
+interface Service {
+ image?: string;
+ command?: string[];
+ environment?: Record<string, string>;
+ volumes?: string[];
+ [key: string]: unknown;
+}
+const text = readFileSync(REPO_COMPOSE, "utf8");
+const compose = parse(text) as { services: Record<string, Service>; volumes: Record<string, unknown> };
+const arango = compose.services.arangodb;
+const command = arango.command ?? [];
+
+const CAPS = [
+ { flag: "--rocksdb.block-cache-size", variable: "IX_ARANGO_BLOCK_CACHE_SIZE", value: "536870912" },
+ { flag: "--rocksdb.enforce-block-cache-size-limit", variable: "IX_ARANGO_ENFORCE_BLOCK_CACHE_LIMIT", value: "true" },
+ { flag: "--rocksdb.total-write-buffer-size", variable: "IX_ARANGO_WRITE_BUFFER_SIZE", value: "268435456" },
+ { flag: "--cache.size", variable: "IX_ARANGO_CACHE_SIZE", value: "134217728" },
+];
+
+describe("docker-compose.standalone.yml: ArangoDB cache caps", () => {
+ it("keeps the existing arangod arguments first and unchanged", () => {
+ expect(command.slice(0, 5)).toEqual(["arangod", "--server.endpoint", "tcp://0.0.0.0:8529", "--vector-index", "true"]);
+ });
+
+ it.each(CAPS)("sets $flag from $variable, defaulting to $value", ({ flag, variable, value }) => {
+ const entries = command.filter((arg) => arg.startsWith(`${flag}=`));
+ expect(entries).toEqual([`${flag}=\${${variable}:-${value}}`]);
+ });
+
+ it("passes nothing else to arangod", () => {
+ expect(command).toHaveLength(5 + CAPS.length);
+ });
+
+ it("caps caches only: no container memory limit, query memory limit or detected-memory override", () => {
+ for (const [name, service] of Object.entries(compose.services)) {
+ expect(service, name).not.toHaveProperty("mem_limit");
+ expect(service, name).not.toHaveProperty("memswap_limit");
+ expect(service, name).not.toHaveProperty("mem_reservation");
+ expect(service, name).not.toHaveProperty("deploy");
+ expect(JSON.stringify(service.environment ?? {}), name).not.toMatch(/ARANGODB_OVERRIDE_DETECTED_TOTAL_MEMORY|Xmx|JAVA_/);
+ }
+ expect(command.join(" ")).not.toMatch(/--query\.(global-)?memory-limit/);
+ });
+
+ it("keeps the image, the data volume and the service names", () => {
+ expect(Object.keys(compose.services)).toEqual(["arangodb", "memory-layer"]);
+ expect(arango.image).toBe("arangodb:3.12.11");
+ expect(arango.volumes).toEqual(["arangodb-data:/var/lib/arangodb3"]);
+ expect(Object.keys(compose.volumes)).toEqual(["arangodb-data"]);
+ expect(arango.environment).toEqual({ ARANGO_NO_AUTH: "1" });
+ });
+});
+
+describe("~/.ix/backend/.env keeps the IX_ARANGO_* overrides", () => {
+ let t: string;
+ beforeEach(() => { t = mkdtempSync(join(tmpdir(), "ix-arango-env-")); });
+ afterEach(() => { rmSync(t, { recursive: true, force: true }); });
+
+ it("rewriting the token leaves a user's cache override in place", () => {
+ const envFile = join(t, ".env");
+ writeFileSync(envFile, "# bigger cache for a big monorepo\nIX_ARANGO_BLOCK_CACHE_SIZE=2147483648\nIX_LOCAL_TOKEN=\n");
+ writeBackendEnv("a".repeat(64), envFile);
+ expect(readFileSync(envFile, "utf8")).toBe(
+ `# bigger cache for a big monorepo\nIX_ARANGO_BLOCK_CACHE_SIZE=2147483648\nIX_LOCAL_TOKEN=${"a".repeat(64)}\n`);
+ writeBackendEnv(undefined, envFile);
+ expect(readFileSync(envFile, "utf8")).toContain("IX_ARANGO_BLOCK_CACHE_SIZE=2147483648\n");
+ });
+
+ it("appends the token after an override-only .env", () => {
+ expect(backendEnvContents("IX_ARANGO_CACHE_SIZE=268435456\n", undefined))
+ .toBe("IX_ARANGO_CACHE_SIZE=268435456\nIX_LOCAL_TOKEN=\n");
+ });
+});