Parallel makeCalls in a command stack?

Skip to first unread message

Aaron Madsen

Jul 16, 2012, 10:55:55 PM7/16/12
to, Lee Barney
 We were discussing internally the idea of running multiple independent makeCalls (in QC Hybrid) in parallel and Josh mentioned that you had done some work that might be related for Android and your Node project. I've copied my notes below and would like your take on this. I'd prefer to use your existing solution or implement something compatible with it.

Our **** Stack is unnecessarily slow because it runs a number of independent start up functions in serial. This is because it needs to run ****() after all of the other functions have completed AND this is the most obvious way to implement this functionality.
I am going to address this in one of two ways - whichever is easier to understand. One is to implement a system of flagging makeCalls so that they are part of a command set, described in the attached notes. This seems like it might be a little complicated, but certainly is possible. However, it involves modifying the heart of QuickConnect's javascript a bit.
The second idea is to break each piece of parallel functionality in to its own command stack, which, when otherwise complete, will call a function that checks to see if it has all of the necessary information to call ****() and, if so, call it. This way, when the last required command stack completes,**** () will be called. I'm going to try this first, since I think it is simpler.
--- attached text file ---

parallel make calls / make_multiple_calls()

Notes on proposed (Javascript) implementation:
- startMakeCallSet(){
  /* - temporarily redefine makeCall to save commands and parameters into an array? */ // not needed
  - temporarily redefines generatePassThroughParameters to return a unique command set identifier
  - creates an array for storing return values for the command set
  - changes default behavior of dispatchBCF so it will continue when undefined is returned and mark that spot in the return value array as needing a value (use unique command set identifier.)

- sendMakeCallSet(){
  /* - send array of makeCalls to native */ // also not needed
  - return generatePassThroughParams to normal
  - return dispatchBCF to normal

* need to modify handleRequestCompletionFromNative code to recognize command set identifiers, fill in the result values where needed, and determine if all results have been received, and, if so, restart the command stack.

 Imagine you have a javascript command stack that needs to complete 6 native command stacks that do not rely on each other before performing another function that relies on all 6. With the current QuickConnect functionality you are required to perform each of the calls to native command stacks serially, over a fairly slow javascript to native interface.
 By adding this functionality, we can still write individual functions focused on triggering the appropriate native command stack, but they will all be passed to native at (nearly) the same time, each running in parallel (on its own native thread, where possible.)
 When the native command stack completes, it will still call handleRequestCompletionFromNative, which will recognize the command stack identifier as part of a command set and put the returned value in to the appropriate location in the command set return values array. When all the command set values have been returned, the command stack will be resumed as normal with the command set return values array as the value for the lastBCFIndex of the previousResults array. The next BCF will be responsible for handling the results appropriately.
 This enables our hypothetical stack to run all its independent native commands in parallel and then run the mutually dependant function after all of them have completed.

Lee Barney

Jul 18, 2012, 5:25:24 PM7/18/12
to Aaron Madsen,

Here is what I currently have.

Node.js: Since node is parallel anyway this design was easy to create. It is possible to execute several command/parameters pairs in parallel. It is also possible to executes a bunch of commands in parallel and share a single set of parameters. In both of these cases there is an optional callback function to be executed when the batch call is complete.

I have attached the API documents for this qc version since I haven't released it quite yet.

Android: I have created the same functionality with the same methods as the node.js implementation in the native Android Java implementation. I can send you this source if you would like.

I am now working on the iOS version of this functionality.

I have not worked on attaching the hybrid js code (via makeCall) to this new native functionality yet but will when I get the iOS version done.

Parallelism is an issue in JScript as you know. I'm still am still working on ideas regarding how to best use this functionality from within JavaScript. It must be remembered that the WebViews are strictly single threaded and queue requests coming from the native side if they are already busy.

I can send you the source in a separate email for the Node.js and Android implementations if you would like to see them.

Reply all
Reply to author
0 new messages