-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Discussion: whisk object vs. context parameter in javascript actions #616
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think that comparing to other serverless architectures is important because it improves the understanding and adoption of openwhisk. Regarding the callback, I agree that #56 is very welcome, especially for modern node runtimes. Comparing to AWS LambdaAWS tweaked the programming model in the node 4.3 runtime, as opposed to the 0.10 runtime.
The Context object holds metadata of the function and about the execution environment, including auth. The user has to call Comparing to Google Cloud FunctionGoogle requires the user to package it's function as a npm module. The function prototype is: The Comparing to Microsoft Azure FunctionAzure's function prototype is event shorter: You end execution with |
This is concern that I have, but I don't know if its part of this issue or it can be handle in a different issue. I would like to have the ability to use export and not forced to have a global we can design what should be exported I'm open to brainstorm on alternatives like convention the benefit is that it's easier to use things like webpack, and other bundlers, and also for using require when it comes to unit testing. |
Global main is definitely not ideal. Export is the way to go. It also enables the use of several functions in the same file. I think webpack'ing is a nice option, but I think it should not be required. Some options to consider:
|
@tuler webpack, was just an example, I agree it should NOT be required. And the other alternatives like using a zip is good to have. I didn't get your 3rd example
You mean a small zip with only the action.js and package.json? and let whisk do the npm install using the package.json? |
Yes. Like you do when you commit your node app to git, excluding node_modules using .gitignore. But I'm not sold on this idea. |
Yeah the penalty in time to invoke an action to get the container warm you would need to wait for npm install, and also hope npm registry or any url your fetching is up :-) But for simple debugging and dev time, it might be useful. |
i think there is benefit in not doing npm install on the server side, since it forces the developer to send over exactly what he wants to be run. i've seen too often issues due to code working on the client side, but didn't work on the server-side since different versions of dependencies were pulled |
I think I agree @mbehrendt Regarding the invoke penalty, I suggested this because I was playing with an architecture that I build a docker image for each function (from a base runtime image) and register it in a private registry. So each function has its docker image. The name of the image is the name of the function. |
yeah, that is a good point. i think in some other issue, @csantanapr had suggested that as well? adding @perryibm , since there might be perf considerations around this |
I can't find the issue now, but in general if I was going into production with an app that every ms counts and I need the highest level of control using a container will be the way to go. and app with multiple dependencies then you can burn this into the container image, no need to fetch the zip of dependencies on cold start. More effort for a novice developer to get this level of control and setup, but this is where some tooling, samples, templates, sdk can come handy to abstract those specific to metadata and developer just worry about the code that will eventually goes into the container. |
Unfortunately, using many docker images wouldn't be free either because the image has to get pulled from some registry. Since we have many invokers and things are quite dynamic, any particular activation might end up having to pull an image as part of its cold start. It might be useful to intercept in the middle and freeze an image after the dependencies but before the user code and re-use these images which are more likely to be share-able. |
One way to overcome, some of this is to use a single image, and build monolitic app with a facade, where it's actually the same docker image, creating multiple actions with same artifact where bound parameters decide which code to run. or creating a single action that handles all events. Yeah I agree cold start of unknown image will need to get downloaded, but once download I believe we cache the image. |
I don't see pulling the image as a big problem if a private registry is part of the architecture. But you have a better understanding of openwhisk architecture to judge it, I'm just starting to play with the code. Sorry to divert from the original discussion, that's why I suggested to create a gitter channel :-) #615 |
I'd like to continue this discussion (focused on the original topic of this issue) here: https://github.com/openwhisk/openwhisk/wiki/Design-Discussion-on-javascript-context |
For node, actions can export a For node, I propose we install into the base the The passing of context parameters via environment object is how we're currently injecting these values into other runtimes; one value per property name. Proposed plan:
Eventually, remove whisk object and environment variables from node actions. |
I give 👍 to the proposal Just a refinement, I think this is more for the implementation details of the openwhisk npm module on how to pick up the env variables. This environment variables could be use by the openwhisk npm module when not running in an action in real runtime, to configure the module. I would like to see an environment variable that provides more info on the whisk edge point to include protocol, and port, this way I can use it for mocking and testing. maybe making |
EDGE_HOST already includes the port. We made a decision long back to only support https at the edge. Hence we striped protocol out. I suggested in the openwhisk-client-js repo a heuristic that satisfies the request you're making. I've also used it in the test attached to the pull request for this issue. |
one quick question -- how would this proposal support situations where the variable value changes while the action invocation is ongoing? |
@mbehrendt Which values do you have in mind? |
Discussing this with @rabbah, I'm going to implement the changes to support apache/openwhisk-client-js#1 and apache/openwhisk-client-js#14. I also had an idea to allow the module constructor to automatically pick up configuration from environment parameters without manual configuration.
The user can still provide this configuration explicitly to override the defaults or work outside the OpenWhisk platform. It will simplify the user experience and reduce the possibility developers make mistakes passing in the configuration, leading to random bugs. |
@jthomas yes, this was I had in mind 👍 for changes to the client js library constructor, use env ad default or override explicit |
@rabbah this might be orthogonal to this issue but wanted to comment.
I left the details of my proposal in my comment in issue #47 #47 (comment) |
Defer to 47 - I don't see what It has to do with this issue. |
@csantanapr great, I've added all the changes now with 2.3.0 |
Pull request #1539 completes the relevant changes for this issue per my proposal above. Remaining are catalog action migrations (apache/openwhisk-catalog#157) and rewriting the following test actions to use
** added todo to remove this asset and corresponding test, no longer valid with adoption of npm openwhisk (conferred with @bjustin-ibm). |
Fixed by 85070a2. |
@domdom82, @csantanapr and @tuler have observed that our current javascript programming model's 'whisk' object probably makes local debugging of javascript actions more difficult than it need be.
To review, the 'whisk' object currently serves two purposes:
For local testing, I think it's probably accurate that it's easier to pass an object to a function than arrange for a global 'whisk' object to be in scope.
Let's discuss possible changes to the programming model here.
Some observations:
The text was updated successfully, but these errors were encountered: