Repository navigation
Description
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
- Create a disposable project on Appwrite 2.7.4 and a key with
databases.read,databases.write,tables.read,tables.write,columns.write,rows.readandrows.write. - With Node 22 or later, run
npm init -yandnpm install [email protected]. Save the script asapp.js. - Set
APPWRITE_ENDPOINT(ending in/v1),APPWRITE_PROJECT_IDandAPPWRITE_API_KEYin your environment. Runnode 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