What's new? | Help | Directory | Sign in
Google
jslibs
standalone Javascript development environment with general purpose native libraries.
  
  
  
  
    
Search
for
Updated Jan 16, 2008 by soubok
Labels: doc
HOWTO  

How to configure jshost memory usage ?

jshost has two arguments that acts on the memory usage:

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 ?

  1. Used the last build of mod_fcgi "Version2.1 ( Feb 15th 2007 )" :
  2. http://fastcgi.coremail.cn/download.htm
  3. Configured Apache 2.2.4 (httpd.conf) with this:
  4. ...
    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>
    ...
  5. for the moment, fcgi.js is quite basic and do not process any script:
  6. LoadModule('jsio');
    new File('C:\\fcgitest\\test.txt').content = File.stdin.Read (9999);
  7. 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.
  8. Last, learn this:
http://www.fastcgi.com/devkit/doc/fcgi-spec.html

Sign in to add a comment