Skip to content

GraphQL adds about 150 ms to a single warm TablesDB row read on Appwrite 2.7.4 #15984

Backlog

Description

@rickylabs

What happened

One GraphQL field that gets a TablesDB row took 155.18 ms wall time and 153.94 ms in Appwrite. The equivalent REST request took 5.35 ms wall time and 4.32 ms in Appwrite. These are medians of 24 interleaved samples with the same API key, row and local connection setup. Session-authenticated reads showed the same delay.

Server timings clustered about 25 ms apart. Appwrite's promise continuation and thenable adoption paths both poll every 25 ms. In a separate Swoole control using the released classes, a result signalled by a channel arrived in 1.14 ms and a pending Appwrite then() continuation took 25.24 ms for the same 1 ms work. Promise continuation · Thenable adoption

Reproduction steps

  1. Create a disposable project on Appwrite 2.7.4 and a key with databases.read, databases.write, tables.read, tables.write, columns.write, rows.read and rows.write.
  2. With Node 22 or later, run npm init -y and npm install [email protected]. Save the script as app.js.
  3. Set APPWRITE_ENDPOINT (ending in /v1), APPWRITE_PROJECT_ID and APPWRITE_API_KEY in your environment. Run node app.js. The script creates and removes its database.
const assert = require('node:assert/strict');
const { performance } = require('node:perf_hooks');
const { Client, ID, TablesDB } = require('node-appwrite');

const endpoint = process.env.APPWRITE_ENDPOINT || '<ENDPOINT>';
const project = process.env.APPWRITE_PROJECT_ID || '<PROJECT_ID>';
const key = process.env.APPWRITE_API_KEY || '<API_KEY>';
const headers = { 'x-appwrite-project': project, 'x-appwrite-key': key, 'content-type': 'application/json' };
const db = new TablesDB(new Client().setEndpoint(endpoint).setProject(project).setKey(key));
const databaseId = ID.unique(), tableId = 'example', rowId = 'example';
const query = `query { tablesDBGetRow(databaseId: "${databaseId}", tableId: "${tableId}", rowId: "${rowId}") { _id } }`;

async function sample(graphql) {
  const path = graphql ? '/graphql' : `/tablesdb/${databaseId}/tables/${tableId}/rows/${rowId}`;
  const start = performance.now();
  const res = await fetch(endpoint + path, {
    headers, method: graphql ? 'POST' : 'GET',
    body: graphql ? JSON.stringify({ query }) : undefined,
  });
  const data = await res.json();
  const wall = performance.now() - start;
  assert(res.ok && !data.errors);
  assert.equal(graphql ? data.data.tablesDBGetRow._id : data.$id, rowId);
  const debug = res.headers.get('x-debug-speed');
  return { wall, debug: debug === null ? null : Number(debug) * 1000 };
}

const median = values => {
  if (values.some(value => value === null)) return 'unavailable';
  values.sort((a, b) => a - b);
  return ((values[11] + values[12]) / 2).toFixed(2);
};

async function run() {
  assert(![endpoint, project, key].some(value => value.startsWith('<')));
  await db.create({ databaseId, name: 'GraphQL benchmark' });
  try {
    await db.createTable({ databaseId, tableId, name: 'Benchmark rows',
      columns: [{ key: 'label', type: 'varchar', size: 32, required: true }] });
    await db.createRow({ databaseId, tableId, rowId, data: { label: 'test' } });
    const samples = { REST: [], GraphQL: [] };
    for (let i = -2; i < 24; i++) {
      for (const mode of i % 2 ? ['GraphQL', 'REST'] : ['REST', 'GraphQL']) {
        const result = await sample(mode === 'GraphQL');
        if (i >= 0) samples[mode].push(result);
      }
    }
    console.table(Object.entries(samples).map(([mode, values]) => ({
      mode, 'wall ms': median(values.map(value => value.wall)), 'X-Debug-Speed ms': median(values.map(value => value.debug)),
    })));
  } finally {
    await db.delete({ databaseId });
  }
}

run().catch(error => {
  console.error('Benchmark failed:', error.message);
  process.exitCode = 1;
});

Expected behavior

When an internal handler completes, its GraphQL continuation can proceed promptly. Request-scoped caller isolation and serial execution of root mutation fields are preserved.

Actual behavior

A single lightweight field adds about 150 ms of server time in the isolated comparison. Timings occur in roughly 25 ms steps, including with the default HTTP worker settings. The delay is the same for one to eight query fields in one document, but it compounds for mutations, whose root fields run in order: eight row updates took 741 ms as one mutation document and 169 ms as an array of eight one-field operations (API key, two HTTP workers). REST is not affected, and parallel REST requests with the same session overlap normally.

Appwrite version and environment

Self-hosted Appwrite 2.7.4, the latest stable release at testing. Linux containers, PostgreSQL, Redis, PHP 8.5.13, Swoole 6.2.5, Node 24 and node-appwrite 32.0.0. The inline run used default HTTP worker settings.

Has this been reported before?

No matching public report for the polling latency surfaced. The request-scoped lock is intentional and has a regression test. #14820 · #14981

Activity

  1. added
    api / graphql
    product / databases
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api / graphqlproduct / databases

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions