Hi All, thanks to everyone who has responded to my questions so far, I've
been able to get everything working (in a test environment) that I was
previously attempting, so now I'm on to the next challenge:

I want to execute a script on an operation by operation basis.

Here's why:
---------------
I need to execute many scripts simultaneously in a server environment
(example: 10,000 scripts running simultaneously, each executing a continuous
work loop). Each script will execute reasonably few instruction per second.
What I need to do is measure out how many operations each script executes
per time period ("operations" can be defined by lines of code, instructions,
or other means as the implementation requires).

My challenge is that once a context starts executing a script, that context
must remain tied to the thread for the duration of the script execution
(please correct me if I'm wrong).

So, a few undesirable options I see so far are:
  1) Instantiate 10,000 threads, each thread can then execute X instructions
then go into an appropriate wait state
(ContextFactory.observeInstructionCount()) would allow this functionality to
work). But maintaining oodles of threads is clearly not desirable, nor
scalable.

  2) Use Apache Commons javaflow to interrupt thread execution while
maintaining the call stack (though this may scale even worse than option 1
as I'm essentially setting up software based context switching and still
keeping all 10k thread states in memory).

What I would really like is to execute a script (or its code) on a line by
line or instruction by instruction basis, where I can measure out exactly
how many instructions/lines/etc are executed by any particular
Context/Thread against a given scope. Then, after X operations I can get
control back to perform other tasks.

This way I could implement a simple thread pool to iterate over all the
scripts, performing a limited set of operations each, while only
maintaining, in memory, a pool of a few context objects + Threads, one root
scope, and the 10k instance scopes (which would be as slim as possible). Not
to mention the benefit that everything could remain serializable in such a
case, which is a big plus for my application.

Is there any chance that such a scenario is possible and I just don't see
how to do it yet? For example, I thought for a moment that I could decompile
a script and run it line by line, but quickly realized that after a function
is complied it would be stored in the scope as a NativeFunction, and a call
to that function would always execute in its entirety before I could receive
control back (not exactly a measured execution). But perhaps there's
something that I'm missing in all of this still.

Thanks for the help!
David




_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to