I have a gen 1 firebase cloud function that iterates through a collection of users and enqueues messages to send to said users by means of a gen 2 firebase task. I upgraded the task to gen 2 in hopes of overcoming cold start delays when sending messages.
As a basic test, I have configured the firebase cloud task with concurrency and queued up a 20 message test, initiated by the function. The observed results are 1 message is dispatched per second. I would have expected all 20 to be delivered rapidly, but perhaps I am missing something. At this point, the gen 2 function is processing no faster than the gen 1 function was.
Currently I am targeting nodejs 14, planning to upgrade to 18 shortly. All 20 messages are dispatched at 1 per second and no errors were encountered in this message test.
Here is the code in question:
const {onTaskDispatched} = require("firebase-functions/v2/tasks");
const {logger} = require("firebase-functions/v2");
const client = require('twilio')(id, auth);
exports.sendMessage = onTaskDispatched({
//minInstances: 0,
memory: '1GiB',
concurrency: 50,
minBackoffSeconds: 10,
maxBackoffSeconds: 600,
rateLimits: {
maxConcurrentDispatches: 100,
}
}, async (req) => {
const message = req.data.message;
if (message) {
try {
const res = await client.messages.create(message);
return res.sid;
} catch (error) {
logger.warn(`Error sending text to: ${message.to} - ${error}`);
throw(error);
}
}
});
You need to set memory to at least 2 GiB:
See the documentation here: https://cloud.google.com/functions/docs/configuring/concurrency