#12 open
sk89q

Memory / CPU script limits

Reported by sk89q | May 7th, 2009 @ 08:23 PM | in Version 0.1.0

Memory and CPU usage / time limits on executed scripts would be nice.

Ref: http://egachine.berlios.de/embed...

Comments and changes to this ticket

  • Paul J. Davis

    Paul J. Davis May 11th, 2009 @ 12:56 AM

    (from [e203f17e196b811162a66a6446180513c0691ea5]) API for limiting resource usage.

    You can now enforce crude resource usage limits for scripts executing in the JS VM. Its not overly granular and has some caveats, but it appears to work.

    To limit the time a script can run:

    >>> rt = spidermonkey.Runtime()
    >>> cx = rt.new_context()
    >>> cx.max_time(5) # Specified in seconds, returns the previous value.
    0
    >>> cx.execute("while(true) {}")
    ...
    RuntimeError
    
    

    To limit the amount of memory is similar:

    >>> rt = spidermonkey.Runtime()
    >>> cx = rt.new_context()
    >>> cx.max_memory(10000) # Specified in bytes, returns the previous value.
    0
    >>> cx.execute("var f = []; var b = 100000; while(b-- > 0) f.push(b*0.9)")
    ...
    RuntimeError
    
    

    At the moment this looks like its limiting resources per context when in reality its per runtime. So if you limit to usage on a context, and some other script in the context is running above that limit, the limited context will fail.

    You can also get the current values without setting:

    >>> cx.max_time(10)
    ...
    >>> cx.max_time()
    10
    >>> cx.max_memory(10000)
    ...
    >>> cx.max_memory()
    10000
    
    

    Some minor tweaks to make the memory limit specified on the Runtime and to improve the reported errors to follow shortly.

    [#12] http://github.com/davisp/python-...

  • Paul J. Davis

    Paul J. Davis May 11th, 2009 @ 01:10 AM

    • State changed from “new” to “resolved”

    (from [28d3cd5ec06a60b8a4824eaa46ac13e41d7108a4]) Change exception types for resource exhaustion.

    Out of memory is now signaled by a MemoryError Too much CPU time is reported as a SystemError

    I'm going to punt on the issue with specifying memory usage limits on contexts when it really refernces the runtime. I don't see a good way to implement it without quite a bit of work. It'll never be specifiable per context, only the api might change to avoid confusion.

    [#12 state:resolved] http://github.com/davisp/python-...

  • Paul J. Davis

    Paul J. Davis May 11th, 2009 @ 09:11 PM

    (from [584ba6f0e3e7078d4a0eeed0c4094a31703a643a]) Updates to the build system.

    Linking against the library works, but importing spidermonkey kills the Python VM because of an unresolved symbol. Can't figure out if this is just OS X's build of libmozjs or if I'm missing a flag.

    [#12] http://github.com/davisp/python-...

  • Paul J. Davis

    Paul J. Davis May 11th, 2009 @ 09:21 PM

    (from [c29ad86edfb992056dbc4b9f1c10f909149abe04]) Updated the README. Thanks Mark Lee.

    [#12] http://github.com/davisp/python-...

  • Paul J. Davis

    Paul J. Davis May 31st, 2009 @ 06:31 AM

    • Milestone set to Version 0.1.0
    • Tag set to resourcelimits
    • State changed from “resolved” to “open”

    When 1.8.1 comes out the memory limit code will be even more ineffective than it already is. I just had the thought that instead of relying on spidermonkey's API to report memory, I could dip back into python for memory reporting some how.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Python/JavaScript bridge module, making use of Mozilla's spidermonkey JavaScript implementation. Allows implementation of JavaScript classes, objects and functions in Python, and evaluation and calling of JavaScript scripts and functions respectively. Borrows heavily from Claes Jacobssen's Javascript Perl module, in turn based on Mozilla's 'PerlConnect' Perl binding.

People watching this ticket

Referenced by

Pages