-
-
Couldn't load subscription status.
- Fork 81
Switch JS runtime caching to sync.Pool #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Just realized a problem, currently we use a loading cache for goja.Runtime caching keyed by ctx. However that means the caching is per transform. We had scenarios in the past where a service handles many concurrent requests, each of which contains a tiny payload that needs to be parsed and transformed. In that situation, the goja.Runtime caching is completely ineffective. Instead, we want to share goja.Runtime across different transforms, as long as javascripts are not called at the same time. Thus the introduction of resource pool. We will adaptively create a number of goja.Runtime in the resource pool, and each of the transforms, concurrent or not, requests a runtime from the pool. We don't want to block, so if there is no available runtime in the pool, while the pool will create a new runtime, it will immediately fail and return. The new execProgram will fallback and create a new runtime. The hope is the resource pool eventually grow to certain size that any concurrent requests would be satisfied. Extensive benchmarks created and verified the new design. With this, now javascript is truly performant enough to fully replace eval.
Codecov Report
@@ Coverage Diff @@ ## master #70 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 29 29 Lines 1257 1266 +9 ========================================= + Hits 1257 1266 +9
Continue to review full report at Codecov.
|
...o set BlockWhenExhausted to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Uh oh!
There was an error while loading. Please reload this page.
Just realized a problem, currently we use a loading cache for
goja.Runtimecaching keyed byctx. However that means the caching is pertransform. We had scenarios in the past where a service handles many concurrent requests, each of which contains a tiny payload that needs to be parsed and transformed. In that situation, thegoja.Runtimecaching is completely ineffective.Instead, we want to share
goja.Runtimeacross different transforms, as long asjavascript()are not called at the same time. Thus the introduction of resource pool. We will adaptively create a number ofgoja.Runtimein the resource pool, and each of the transforms, concurrent or not, requests a runtime from the pool. The hope is the resource pool eventually grow to certain size that any concurrent requests would be satisfied. The pool is also configured to have a minimum idling runtimes, so that when eviction kicks in, it won't completely clear up the cache.Extensive benchmarks created and verified the new design. With this, now javascript is truly performant enough to fully replace eval.
[update] - given my simple use case of the resource pool: no max limit, no blocking, etc. there is simply no reason to use this full featured resource pool - instead use the much simpler and more performant
sync.Pool. And benchmark proved it's much faster and nowjavascriptis nearly on par witheval; and concurrent performance is much better than the full-fledged resource pool usage.