Subj : SpiderMonkey and threads To : netscape.public.mozilla.jseng From : Mads Bondo Dydensborg Date : Tue Mar 29 2005 02:39 pm Hi all I am trying to learn more about the way threads should work with spidermonkey. My use case is a program running several hundreds instances of the same script - think php like, serving 100s of pages at the same time that is the output of a spidermonkey script. Each request will be managed by its own thread. Now, all scripts are the same. What is the most ressource efficient way to organize this? Should the SpiderMonkey engine be compiled with thread support, or should I organize for each thread to run its own engine? I am a bit worried about the overhead in setting up a runtime, context, and compile the script for each request. (I guess I can pool a number of runtimes, and have my threads acquire them from there, and placing them back when they are done). Is there a way to share scripts across contexts, or runtimes? It would seem that having 100 instances of essentially the same script is a bit redundant in memory use. Can I share scripts by creating a script object, and pass this to JS_ExecuteScript? (Objects are shared across contexst, I believe). If I set the global object using JS_SetGlobalObject, and execute a script associated with this, can this global object be reused across several contexts? (I believe this is the meaning of the figure 1.3 in the guide, yes?) What is the impact of using 100 of threads on a single runtime, if all threads wants to e.g. call the Date Object? Sorry for my wild "shotgun" questions - google unfortunately does not turn up a lot, other than "SpiderMonkey supports multithreaded execution". Which is nice to know, but not really very helpful ;-) I did read the docs for JS_SetContextThread, JS_GetContextThread and JS_ClearContextThread, but did not learn anything substantial. Regards and thanks in advance, Mads .