Hello, I'm try to use cloudflare features I didn't experimented, and reached to HyperDrive.
Currently, my service is growing very fast, so getting out of free tier, keep draining my budget double at month - so I decided to try HyperDrive instead of D1.
It works great at first time, but with 1 hours of monitering I see very big problem - HyperDrive connection occurs worker timeout with code force exit.
I don't know why it is, but guessing it's related to high amount of concurrent database connection.
My service is getting average 10 request per second, and this means I need 30+ concurrent connection at traffic burst timing.
How can I deal it with HyperDrive, can anyone give some advice to me?
Using PosgreSQL + TimescaledDB + HyperDrive for real-time analysis.
Getting this error for now.
The Workers runtime canceled this request because it detected that your Worker's code had hung and would never generate a response. Refer to: https://developers.cloudflare.com/workers/observability/errors/"
Using this test code:
private static async appendLog(c: DrizzleContext, image: ImageType) {
try {
await GeneralHyperdrive.getOrCreateDrive(
"log",
c.context.env.SUB_DATABASE
)
.db()
.insert(LOG_TABLE)
.values({
time: new Date(),
articleid: image.articleId,
traffic: image.fileSize,
referer:
c.context.req.header("Referer") ?? c.context.req.header("referer"),
});
} catch (e) {}
}
// class GenericHyperdrive
static getOrCreateDrive = function (
name: string,
drive: Hyperdrive | undefined = undefined
) {
if (GeneralHyperdrive.drives.has(name)) {
return GeneralHyperdrive.drives.get(name);
}
const pool = new Pool({
connectionString: drive.connectionString,
});
const db = drizzle({ client: pool });
const newDrive = new GeneralHyperdrive(db);
return newDrive;
};