How to preload JS code and have it accessible in different isolates or contexts #169
Replies: 1 comment
-
Javet is a wonderful scripting engine for SaaS supporting multi-tenancy with complete data segregation among the tenants. Here are my 2 cents for your reference.
The memory or threading model in Nashorn is off the ECMAScript spec so that there are many undefined behaviors under race condition. I guess (please correct me if I'm wrong) in your case your application only allows read access to the shared data to avoid those gray area. Both Javet and GraalJS don't leave room for those undefined behaviors. That implies you need to find a new way, of course, this discussion as a beginning.
I my humble opinion, it concerns me on the following.
The execution among multiple V8 contexts in one V8 isolate is single-threaded. I don't think that's what you expect, please correct me if I'm wrong. SuggestionMy suggestion is Javet Engine Pool + ES Module. Javet Engine PoolJavet Engine Pool works like a DB connection pool. It allows multiple tenants to reuse idle V8 isolates without creating/destroying V8 isolates frequently. ES ModulesESM can be used to cache shared business logic and data among the tenants. Those ES modules are actively cached by V8. Pros and ConsPros
Cons
Hope these make sense. You may visit discord to discuss with me in real-time if you have any further questions. |
Beta Was this translation helpful? Give feedback.
-
This may be an odd situation, But I'll give some background.
I work at multi-tenet SaaS company that allows people to create custom apps, etc using JavaScript. We currently use Nashorn. To save load time and memory we create a single Nashorn engine per app and that single engine is accessed by all accounts and we use a separate context per account to prevent one account from storing a global variable that can be accessed by another account.
With Nashorn on the way out we are looking at replacing it.
So what I need assistance with is a way to efficiently share code across multiple contexts or isolates in a V8 engine without unnecessarily duplicating memory usage.
From my research this is possible to have a V8 Isolate then creating different contexts but setting each context security key to a unique value using
v8::Context::SetSecurityToken()
I have looked at GraalJS as well, But it has some performance issues and other limitations. So I'm hoping Javet is the way forward.
Beta Was this translation helpful? Give feedback.
All reactions