You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by al...@apache.org on 2020/04/15 01:21:53 UTC

[openwhisk-wskdebug] branch speed2 created (now 931f5fc)

This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a change to branch speed2
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


      at 931f5fc  performance: load action sources lazily on container

This branch includes the following new commits:

     new 931f5fc  performance: load action sources lazily on container

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[openwhisk-wskdebug] 01/01: performance: load action sources lazily on container

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a commit to branch speed2
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git

commit 931f5fcaae7995decb3c190217c2b2089ee80361
Author: Alexander Klimetschek <ak...@adobe.com>
AuthorDate: Tue Apr 14 18:20:35 2020 -0700

    performance: load action sources lazily on container
    
    - big improvement for larger actions with many npm modules, from ~9 sec to ~4sec startup
---
 src/kinds/nodejs/mount-plain.js   |  3 ---
 src/kinds/nodejs/mount-require.js | 30 ++++++++++++++++++++----------
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/src/kinds/nodejs/mount-plain.js b/src/kinds/nodejs/mount-plain.js
index 1f4557e..9298bf0 100644
--- a/src/kinds/nodejs/mount-plain.js
+++ b/src/kinds/nodejs/mount-plain.js
@@ -41,9 +41,6 @@ function load(path) {
     return fn;
 }
 
-// load and validate on /init for quick feedback
-load(path);
-
 // eslint-disable-next-line no-unused-vars
 function main(args) { // lgtm [js/unused-local-variable]
     // load code again on every new invocation
diff --git a/src/kinds/nodejs/mount-require.js b/src/kinds/nodejs/mount-require.js
index 44be9f8..6c4cbbe 100644
--- a/src/kinds/nodejs/mount-require.js
+++ b/src/kinds/nodejs/mount-require.js
@@ -26,24 +26,34 @@ const mainFn = "$$main$$";
 // name of module file (for helpful errors)
 const sourceFile = "$$sourceFile$$";
 
-// load and validate on /init for quick feedback
-try {
-    require(path);
-} catch (e) {
-    throw `Cannot load module '${sourceFile}': ${e}`;
-}
-if (typeof require(path)[mainFn] !== "function") {
-    throw `'${mainFn}' is not a function in '${sourceFile}'. Specify the right function in wskdebug using --main.`;
-}
-
 function clearEntireRequireCache() {
     Object.keys(require.cache).forEach(function(key) {
         delete require.cache[key];
     });
 }
 
+let firstRun = true;
+
 // eslint-disable-next-line no-unused-vars
 function main(args) { // lgtm [js/unused-local-variable]
+
+    if (firstRun) {
+        const start = Date.now();
+        console.log(`[wskdebug] loading action sources from ${sourceFile}`);
+        // validation with better error messages
+        try {
+            require(path);
+        } catch (e) {
+            throw `Cannot load module '${sourceFile}': ${e}`;
+        }
+
+        if (typeof require(path)[mainFn] !== "function") {
+            throw `'${mainFn}' is not a function in '${sourceFile}'. Specify the right function in wskdebug using --main.`;
+        }
+        firstRun = false;
+        console.log(`[wskdebug] loaded in ${Date.now() - start} ms.`);
+    }
+
     // force reload of entire mounted action on every invocation
     clearEntireRequireCache();