|
|
How to configure jshost memory usage ?
jshost has two arguments that acts on the memory usage:
- -m <size_in_MB> is used to set the maximum memory (in megabyte) a script can use. Beyond this limit, the script will crash with an "Out of memory" error. (default setting is no limit)
- -n <size_in_MB> is the number of megabytes a script can allocate before the garbage collector is called. (default setting is no limit)
It is important to note that the value used by -m and -n flags are only related to the memory allocations made internally by SpiderMonkey. If a native class or function wrapped by a JavaScript object allocates memory, this amount of memory it is not taken in account for -m and -n calculation. This can result in a bigger memory usage that you have specified with -m and -n flags.
Note: when SpiderMonkey allocates system memory, it does not necessarily free it instantly. To enhance performances, it will keep it for later use. For example, the following script will allocate a lot of memory without returning it to the system:
var a=[]; for (var i=0; i<1024*1024; i++) a.push([[]]); a=undefined; CollectGarbage();
How to avoid loading a module in the global scope ?
To achieve this, you have to change the current object of LoadModule's call:
var jsstd = {};
LoadModule.call( jsstd, 'jsstd' );
jsstd.Print( jsstd.IdOf(1234), '\n' );This acts as namespaces.
You are free to define your own LoadModule function. eg.
function MyLoadModule( moduleName ) {
var ns = global[moduleName] = {};
return LoadModule.call( ns, moduleName );
}How to configure jshost to run as FastCGI ?
- Used the last build of mod_fcgi "Version2.1 ( Feb 15th 2007 )" :
- Configured Apache 2.2.4 (httpd.conf) with this:
- for the moment, fcgi.js is quite basic and do not process any script:
- Created a dummy script in .../Apache2.2/cgi-bin, and when you run this script, fcgi.js is executed via jshost.exe and test.txt is filled with consistent data.
- Last, learn this:
http://fastcgi.coremail.cn/download.htm
... LoadModule fcgid_module modules/mod_fcgid.so ... <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin"> SetHandler fcgid-script Options execCGI AllowOverride None Order allow,deny Allow from all FCGIWrapper "C:\fcgitest\jshost.exe C:\fcgitest\fcgi.js" .js </Directory> ...
LoadModule('jsio');
new File('C:\\fcgitest\\test.txt').content = File.stdin.Read (9999);http://www.fastcgi.com/devkit/doc/fcgi-spec.html
Sign in to add a comment
