Lots of updates, concurrency and memory management #68

Merged
merged 9 commits into from Apr 8, 2012

2 participants

@Licenser

I implemented isolates as encapsulation for all VM processes, this way they don't get into eachothers contexts. Some restructuring was needed and my first fear was that I'd break the memory management, but actually isolates improved the situation.

new features are:

  • Isolation of each erlv8_vm:start() vm into an own isolate.
  • erlv8_vm:kill(VM) - kills the running script.
  • fix of an memory leak when creating and discarding VM's (at least mostly)

All but one test are running (no degradation detected).

For the memory issue I rant he following test:

application:start(erlv8).
S = lists:seq(0, 10000, 1).
lists:map(fun(I) -> {ok, VM} = erlv8_vm:start(), erlv8_vm:stop(VM) end,S).

The code creates and discards 10k VM's here are my results (taken from top not 100% accurate but it shows the tendency good enough)

current HEAD versionn

31023  beam.smp         99.8      02:53.14 16/1  0    8390  20348  1119M  216K   1108M  1258M  4179M  31023 481   running  501  331422    202     52435      26214      883498+   13457640    413992+   563     39M    7770K  licenser
# Fatal error in CALL_AND_RETRY_2
# Allocation failed - process out of memory
#
Abort trap: 6

New Isolate Version:

31038  beam.smp         0.0       04:30.86 16    0    10054 10171  131M   216K   136M   230M   3183M  31038 481   sleeping 501  3414413   202     200297     100147     1426957+  15429276    736603+   0       43M    5994K  licenser
[ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,
 ok,ok,ok,ok,ok,ok,ok,ok,ok,ok|...]
Licenser added some commits Feb 21, 2012
@Licenser Licenser * Added tracing with the TRACE macro.
* added isolates.
* moved global objects into vm/isolate scope
* removed (commented) all Dispose calls (they case segfaults :( ) - TODO: fix this
* added some helpers in make and extended debug functionatlity
86b5183
@Licenser Licenser * Some testing in regards of memory leakage.
* Figured out that isolates should discard everything on their deletion :)
01c9840
@Licenser Licenser Fixed degration in the use of global contexts. 2ffcdcf
@yrashk
beam.js member

Before I will have a chance to check this out for real, what's the test that's failing?

@Licenser

the following test:

Vanilla erlv8:

..Testing erlv8_tests:prop_to_js_string/0
!
Failed: After 3 test(s).
[{set,{var,1},{call,erlv8_tests,start_vm,[]}},{set,{var,2},{call,erlv8_tests,run_tests,[{var,1}]}},{set,{var,3},{call,erlv8_tests,exit_vm,[{var,1}]}},{set,{var,4},{call,erlv8_tests,start_vm,[]}},{set,{var,5},{call,erlv8_tests,run_tests,[{var,4}]}},{set,{var,6},{call,erlv8_tests,exit_vm,[{var,4}]}},{set,{var,7},{call,erlv8_tests,start_vm,[]}},{set,{var,8},{call,erlv8_tests,run_tests,[{var,7}]}},{set,{var,9},{call,erlv8_tests,exit_vm,[{var,7}]}}]

Shrinking Testing erlv8_tests:prop_to_js_string/0
.Testing erlv8_tests:prop_to_js_string/0
..Testing erlv8_tests:prop_to_js_string/0
.Testing erlv8_tests:prop_to_js_string/0
..(3 time(s))
[{set,{var,1},{call,erlv8_tests,start_vm,[]}},{set,{var,2},{call,erlv8_tests,run_tests,[{var,1}]}}]
erlv8_tests:123: erlv8_test_ (PropEr tests)...*failed*
::{assertEqual_failed,[{module,erlv8_tests},
                     {line,109},
                     {expression,"proper : quickcheck ( statem ( ) , [ { on_output , fun ( Format , Data ) -> io : format ( standard_error , Format , Data ) end } , { numtests , 10 } ] )"},
                     {expected,true},
                     {value,false}]}
  output:<<"History: [{{state,[],[]},<0.755.0>}]
State: {state,[<0.755.0>],[]}
Result: {exception,error,function_clause,
                   [{proper,'-clean_stacktrace/1-fun-0-',
                            [{erlang,iolist_to_binary,[[2096]],[]}],
                            []},
                    {lists,splitwith,3,[{file,"lists.erl"},{line,1337}]},
                    {proper,clean_stacktrace,1,[]},
                    {proper,apply_args,3,[]},
                    {proper,perform,7,[]},
                    {proper,inner_test,2,[]},
                    {proper,mfa_test,3,[]},
                    {proper,'-multi_test/3-lc$^1/1-1-',3,[]}]}
History: [{{state,[],[]},<0.771.0>}]
State: {state,[<0.771.0>],[]}
Result: {exception,error,function_clause,
                   [{proper,'-clean_stacktrace/1-fun-0">>...

=======================================================
  Failed: 1.  Skipped: 0.  Passed: 79.
ERROR: One or more eunit tests failed.
make: *** [test] Error 1

isolate erlv8

.Testing erlv8_tests:prop_to_js_string/0
!
Failed: After 1 test(s).
An exception was raised: error:badarg.
Stacktrace: [{erlang,iolist_to_binary,[[552545]],[]},
             {erlv8_tests,'-prop_to_js_string/0-fun-0-',1,
                          [{file,"test/erlv8_tests.erl"},{line,98}]}].
[552545]

Shrinking .(1 time(s))
[256]

!
Failed: After 2 test(s).
[{set,{var,1},{call,erlv8_tests,start_vm,[]}},{set,{var,2},{call,erlv8_tests,run_tests,[{var,1}]}},{set,{var,3},{call,erlv8_tests,exit_vm,[{var,1}]}},{set,{var,4},{call,erlv8_tests,start_vm,[]}}]

Shrinking Testing erlv8_tests:prop_to_js_string/0
.Testing erlv8_tests:prop_to_js_string/0
(1 time(s))
[{set,{var,1},{call,erlv8_tests,start_vm,[]}},{set,{var,2},{call,erlv8_tests,run_tests,[{var,1}]}}]
erlv8_tests:123: erlv8_test_ (PropEr tests)...*failed*
::{assertEqual_failed,[{module,erlv8_tests},
                     {line,109},
                     {expression,"proper : quickcheck ( statem ( ) , [ { on_output , fun ( Format , Data ) -> io : format ( standard_error , Format , Data ) end } , { numtests , 10 } ] )"},
                     {expected,true},
                     {value,false}]}
  output:<<"History: [{{state,[],[]},<0.656.0>},
          {{state,[<0.656.0>],[]},[{erlv8_tests,prop_to_js_string,0}]}]
State: {state,[],[<0.656.0>]}
Result: {postcondition,false}
History: [{{state,[],[]},<0.666.0>}]
State: {state,[<0.666.0>],[]}
Result: {exception,error,badarg,
                   [{erlang,iolist_to_binary,[[225215]],[]},
                    {proper_stdgen,'-binary_string/1-fun-0-',1,
                                   [{file,"src/proper_stdgen.erl"},{line,35}]},
                    {proper_gen,generate,3,
                                [{file,"src/proper_gen.erl"},{line,155}]},
                    {proper_gen,generate,1,
                                [{file,"src/proper_gen.erl"},{line,105}]},
                    {proper_gen,generate,3,
                                [{file,"src/">>...

=======================================================
  Failed: 1.  Skipped: 0.  Passed: 79.
ERROR: One or more eunit tests failed.
make: *** [test] Error 1

feel free to pull in a branch or just clone my fork to try out stuff first :)

@Licenser

also now including the fix for the 0mq repo move.

@yrashk yrashk merged commit 2ded86a into beamjs:master Apr 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment