<div>Hello! <br></div><br> I wrote simple benchmark code to measure floating-point Erlang performance. And seems that code gets Erlang system into a deadlock :-p <br><br> The thing is that my code doing VERY simple thing - it first generates big list of pairs of Euclidian vectors, then in loop performs sequential mult-add operation on each element. <br>
When I start one such process per CPU core and list is big enough, the Erlang systems quickly stops responding. <br><br> The code is: <br><br> -module ( bug ). <br> -export ( [start/0] ). <br><br> -record ( vec3, { x=0, y=0, z=0 } ). <br>
<br><br> vec3ma( V0, V1, K ) when is_record( V0, vec3 ) and is_record( V1, vec3 ) and is_number( K ) -> <br> #vec3{ x = V0#vec3.x + V1#vec3.x * K, y = V0#vec3.y + V1#vec3.y * K, z = V0#vec3.z + V1#vec3.z * K }. <br><br>
%create test data <br> makeVecTestList( L, 0 ) -> L; <br> makeVecTestList( L, N ) -> <br> E = { #vec3{ x = N * 10.0, y = 20.0, z = 30.0 }, #vec3{ x=10.0, y=20.0, z=-40.0 } }, <br> makeVecTestList( [ E|L ], N - 1 ). <br>
<br> %Test list-processing code <br> proc( L ) -> proc( L, [] ). <br> proc( [], Acc ) -> Acc; <br> proc( [ { P, V } | T ], Acc ) -> proc( T, [ { vec3ma( P, V, 0.11 ), V } | Acc ] ). <br><br> %process loop <br> vecTestLoop( L, T, I ) -> <br>
Now = now(), <br> DT = timer:now_diff( Now, T ) * 1.0e-3, <br> io:format( "Step~p: ~p ms\n", [I, DT] ), <br> vecTestLoop( proc( L ), Now, I ). <br><br> start() -> <br> L = makeVecTestList( [], 1000000 ), <br>
io:format( "Running test with: ~p\n", [length(L)] ), <br> spawn( fun() -> vecTestLoop( L, now(), 1 ) end ), <br> spawn( fun() -> vecTestLoop( L, now(), 2 ) end ), <br> spawn( fun() -> vecTestLoop( L, now(), 3 ) end ), <br>
spawn( fun() -> vecTestLoop( L, now(), 4 ) end ). <br><br><br> I used next test-cases: <br><br> AMD 64 2 core, 3.1 GHZ, Windows XP, Erlang R14B04: <br> - Works well with one process and any list that fits into memory <br>
- Works well with two processes and list of 500000 elements <br> - Hangs in about 30-60 seconds with list of 750000 elements <br> - Hangs almost immediately with list of 1000000 elements <br><br> Intel Quad 2.67 GHz, Windows 7 x64, Erlang R14B04: <br>
- Works well with one process and any list that fits into memory <br> - Hangs in about 30-60 seconds with list of 1000000 elements <br> - Hangs almost immediately with list of 1500000 elements <br><br> This looks very similar to deadlock - when normal iterations freeezes, the erl.exe cannot be stopped with Ctrl+C/Break, typing "q()." etc, and starts to load ONLY ONE CORE. Though while it still alive, it consumes all cores. <br>
<br> Memory consumption by erl.exe was about or even under 1 GB in all cases. <br><br>