From 48bcee30e9b6c5b967735d50877c5c5ea5b530ed Mon Sep 17 00:00:00 2001 From: Ildar Nurislamov Date: Fri, 15 Dec 2023 20:37:35 +0400 Subject: [PATCH] rotor: increase isolate-vm pool --- .../src/functions/lib/mongodb.ts | 2 +- .../core-functions/src/functions/lib/store.ts | 34 +++++++++++++------ .../src/functions/udf_wrapper.ts | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/libs/core-functions/src/functions/lib/mongodb.ts b/libs/core-functions/src/functions/lib/mongodb.ts index 22180944e..c44e4de42 100644 --- a/libs/core-functions/src/functions/lib/mongodb.ts +++ b/libs/core-functions/src/functions/lib/mongodb.ts @@ -17,7 +17,7 @@ async function createClient() { log.atInfo().log(`Connecting to MongoDB server...`); // Create a new MongoClient - const client = new MongoClient(mongodbURL); + const client = new MongoClient(mongodbURL, { readPreference: "nearest" }); // Connect the client to the server (optional starting in v4.7) await client.connect(); // Establish and verify connection diff --git a/libs/core-functions/src/functions/lib/store.ts b/libs/core-functions/src/functions/lib/store.ts index b3df91dab..86d05ca39 100644 --- a/libs/core-functions/src/functions/lib/store.ts +++ b/libs/core-functions/src/functions/lib/store.ts @@ -87,7 +87,10 @@ export const createMongoStore = (namespace: string, mongo: MongoClient, defaultT return { get: async (key: string) => { - const res = await mongo.db(dbName).collection(namespace).findOne({ _id: key }); + const res = await mongo + .db(dbName) + .collection(namespace) + .findOne({ _id: key }, { readPreference: "nearest" }); return res ? res.value : undefined; }, set: async (key: string, obj: any, opts?: SetOpts) => { @@ -95,21 +98,30 @@ export const createMongoStore = (namespace: string, mongo: MongoClient, defaultT const ttl = getTtlSec(opts); const expireAt = new Date(); expireAt.setSeconds(expireAt.getSeconds() + ttl); - await mongo.db(dbName).collection(namespace).replaceOne( - { _id: key }, - { - value: obj, - expireAt, - }, - { upsert: true } - ); + await mongo + .db(dbName) + .collection(namespace) + .replaceOne( + { _id: key }, + { + value: obj, + expireAt, + }, + { upsert: true, writeConcern: { w: 1, journal: false } } + ); }, del: async (key: string) => { await ensureCollection(); - await mongo.db(dbName).collection(namespace).deleteOne({ _id: key }); + await mongo + .db(dbName) + .collection(namespace) + .deleteOne({ _id: key }, { writeConcern: { w: 1, journal: false } }); }, ttl: async (key: string) => { - const res = await mongo.db(dbName).collection(namespace).findOne({ _id: key }); + const res = await mongo + .db(dbName) + .collection(namespace) + .findOne({ _id: key }, { readPreference: "nearest" }); return res ? Math.max(Math.floor((res.expireAt.getTime() - new Date().getTime()) / 1000), 0) : -2; }, }; diff --git a/libs/core-functions/src/functions/udf_wrapper.ts b/libs/core-functions/src/functions/udf_wrapper.ts index 7c246750d..bc0a430a3 100644 --- a/libs/core-functions/src/functions/udf_wrapper.ts +++ b/libs/core-functions/src/functions/udf_wrapper.ts @@ -29,7 +29,7 @@ export const UDFWrapper = (functionId, name, functionCode: string): UDFWrapperRe let isolate: Isolate; try { //const wrappedCode = `let exports = {}\n${functionCode}\n${wrapperJs}`; - isolate = new Isolate({ memoryLimit: 10 }); + isolate = new Isolate({ memoryLimit: 128 }); const context = isolate.createContextSync(); const jail = context.global;