Ecmascript module

Hi,

I’ve started to build an nginx module to process server-side
ecmascript (javascript) by embedding the spidermonkey engine. I’ve got
a (very) rough proof of concept hacked together just now, but after
about 30-50 requests the I can’t allocate enough memory to build the
spidermonkey runtime.

I’m new to C and just skim-read the white book to get this far so I
expect I am just making naive C mistakes.

What I couldn’t understand is that the same jsapi code outside of the
nginx module never seemed to have the allocation issues.
And if it was a memory allocation issue… wouldn’t my worker
processes rise above 2MB?

Sorry for the vague message, but if someone could give me a nudge in
the right direction of what might be happening so I can get back to
learning it would be much appreciated!

here’s my example so far:

PS: thanks “Evan M.” for the module tutorial :wink:

On Mon, Jan 19, 2009 at 02:00:26PM +0000, Chris Farmiloe wrote:

nginx module never seemed to have the allocation issues.
And if it was a memory allocation issue… wouldn’t my worker
processes rise above 2MB?

Sorry for the vague message, but if someone could give me a nudge in
the right direction of what might be happening so I can get back to
learning it would be much appreciated!

here’s my example so far:

http://github.com/chrisfarms/nginx_ecmascript_module/blob/0d970a33771c4cdbec2293c5c5db9f34191e7ffa/ngx_http_ecmascript_module.c

There is already an attempt to embedd SpiderMonkey:
http://www.cmsbuilder.ru/files/nginx.js/ngx_http_js_module-0.1.tgz

(and some comments in Russian):
http://www.cmsbuilder.ru/blog/2008/12/07/ngx_http_js_module-01/
http://www.cmsbuilder.ru/blog/2008/11/30/nginx-js/

You may look this implementation.

Thanks! I’ll take a look

Chris Farmiloe wrote:

Hi,

I’ve started to build an nginx module to process server-side
ecmascript (javascript) by embedding the spidermonkey engine.
This is something I’ve been hoping would be developed for a while now.
However, wouldn’t it be better to have the spidermonkey engine running
as an SGI/FCGI module rather than embedded, to open it up to more
services?

Phillip B Oldham
The Activity People
[email protected] mailto:[email protected]


Policies

This e-mail and its attachments are intended for the above named
recipient(s) only and may be confidential. If they have come to you in
error, please reply to this e-mail and highlight the error. No action
should be taken regarding content, nor must you copy or show them to
anyone.

This e-mail has been created in the knowledge that Internet e-mail is
not a 100% secure communications medium, and we have taken steps to
ensure that this e-mail and attachments are free from any virus. We must
advise that in keeping with good computing practice the recipient should
ensure they are completely virus free, and that you understand and
observe the lack of security when e-mailing us.

On Jan 19, 2009, at 15:41 , Phillip B Oldham wrote:

Chris Farmiloe wrote:

Hi,

I’ve started to build an nginx module to process server-side
ecmascript (javascript) by embedding the spidermonkey engine.
This is something I’ve been hoping would be developed for a while
now. However, wouldn’t it be better to have the spidermonkey engine
running as an SGI/FCGI module rather than embedded, to open it up to
more services?

I have to agree with this. There are a couple of attempts out there
such as http://code.google.com/p/jslibs/


Phillip B Oldham
The Activity People
[email protected]

/J

That would certainly make it more portable among other servers, but I
do like the simplicity of letting the nginx worker host the request.

That said, making an HTTP server for the jslibs collection might also
be fun, then nginx could just play proxy again.

Chris Farmiloe wrote:

Sorry for the vague message, but if someone could give me a nudge in
the right direction of what might be happening so I can get back to
learning it would be much appreciated!

Hi, Chris. That attempt of embedding spidermonkey
(http://www.cmsbuilder.ru/files/nginx.js/ngx_http_js_module-0.1.tgz) in
nginx was mine :slight_smile: I didn’t know that it can be interesting for someone
elsewhere than Russia. So I’v posted that review only in my native
language, russian.

If you kept the interest till now, please contact me via email
([email protected]). It will be grate to talk about js in nginx :slight_smile:

Took my legs in arms and followed your example, Chris: