When using the node.js client for firebase admin, calling DocumentReference.set blocks the nodejs event loop for approximately 200ms for every write. 200ms approximately corresponds to the latency expected by a network round-trip to and from the firestore server. This is a major cause of slowdown for my application.
The documentation for DocumentReference.set seems to imply that this should be a non-blocking call because the method returns a promise (note that I did not include an await in the code, so I do not wait for the promise to resolve).
Is there a way to make this call not block the node.js event loop?
Code
logger.info("start of DB write")
const collectionReference = this.db.collection("notification");
logger.info("Before DB reference");
const documentReference = collectionReference.doc(key);
logger.info("Before DB write");
documentReference.set(value);
logger.info("after DB write");
Logs from the server
{"label":"index.js","level":"info","message":"start of DB write","timestamp":"2022-06-01T09:13:13.684Z"}
{"label":"index.js","level":"info","message":"Before DB reference","timestamp":"2022-06-01T09:13:13.684Z"}
{"label":"index.js","level":"info","message":"Before DB write","timestamp":"2022-06-01T09:13:13.684Z"}
{"label":"index.js","level":"info","message":"after DB write","timestamp":"2022-06-01T09:13:13.867Z"}
Environment details
- OS: node:16-alpine (docker image)
- Node.js version: v16.13.2
- npm version: 8.5.5
@google-cloud/firestoreversion: 4.15.1