<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi,</div><div><br></div><div>Yes, that's true. But the "try_steal_task()" afterwards is also controlled by ERTS_SMP macro. It doesn't make any sense to talk about workload balance outside multi-processor environment. I'm just wondering why "check_balance" is needed while there exists work stealing(try_steal_task). </div><div><br></div><div>Cheers</div><br><div><div>On May 2, 2012, at 12:04 PM, xu yu wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi,<div><br></div><div>"check_balance" controlled by "ifdef ERTS_SMP", so...<br><br><div class="gmail_quote">2012/4/27 "Siyao Zheng(郑思遥)" <span dir="ltr"><<a href="mailto:zhengsyao@gmail.com" target="_blank">zhengsyao@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">Hi,<br>
<br>
schedule(), in which check_balance() is only called.<br>
<br>
In schedule(), when check_balance_reds reaches zero, scheduler decides to "check_balance". But later in schedule(), when scheduler finds run queue being empty, it will try to steal task from other schedulers (by calling try_steal_task()), which is also a load balance mechanism. I'm just wondering what the purpose of check_balance().<br>
<br>
Cheers<br>
<span class="HOEnZb"><font color="#888888">Siyao<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Apr 27, 2012, at 9:40 PM, Zabrane Mickael wrote:<br>
<br>
> Hi Siyao,<br>
><br>
> Which "check_balance" you've commented out?<br>
><br>
> Here is what I found so far:<br>
><br>
> $ find /otp_src_R15B01 -type f | xargs grep check_balance | grep -v matches<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: int forced_check_balance;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c:check_balance(ErtsRunQueue *c_rq)<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c:# error check_balance() assumes ERTS_MAX_PROCESS < (1 << 27)<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: c_rq->check_balance_reds = INT_MAX;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: c_rq->check_balance_reds = INT_MAX;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: rq->check_balance_reds = ERTS_RUNQ_CALL_CHECK_BALANCE_REDS;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: * check_balance() is never called in more threads<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: forced = balance_info.forced_check_balance;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: balance_info.forced_check_balance = 0;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: c_rq->check_balance_reds = INT_MAX;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: rq->check_balance_reds = INT_MAX;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: rq->check_balance_reds = ERTS_RUNQ_CALL_CHECK_BALANCE_REDS;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: rq->check_balance_reds = ERTS_RUNQ_CALL_CHECK_BALANCE_REDS;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: balance_info.forced_check_balance = 0;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: (RQ)->check_balance_reds = ERTS_RUNQ_CALL_CHECK_BALANCE_REDS; \<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: balance_info.forced_check_balance = 1;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: ERTS_RUNQ_IX(0)->check_balance_reds = 0;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: if (rq->check_balance_reds <= 0)<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.c: check_balance(rq);<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.h: int check_balance_reds;<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.h: (RQ)->check_balance_reds -= (REDS); \<br>
> /opt/otp_src_R15B01/erts/emulator/beam/erl_process.h: (RQ)->check_balance_reds -= (REDS);<br>
> [...]<br>
><br>
> For OTP Team: is this dangerous ?<br>
><br>
> Regards,<br>
> Zabrane<br>
><br>
><br>
> On Apr 27, 2012, at 1:23 PM, Siyao Zheng(郑思遥) wrote:<br>
><br>
>> Hi,<br>
>><br>
>> In SMP version of Erlang, every scheduler periodically call "check_balance()" to check load balance among all schedulers, then it might migrate some processes to balance load, or shut down some schedulers with low load. Does anyone know why scheduler should do this? check_balance() is quite a big one, and it has to lock every run queue when it checks the run queue. I think it's quite a big cost here. The work stealing at each schedule step afterwards actually does work load balance very well. Actually after I comment out the check_balance() step and run BigBang and Hackbench benchmarks, they are really faster!<br>
>><br>
>> So, I wonder what is the purpose of check_balance() step here, if it is related to scalability on many core processors or something, and if there is any other benchmark I can run to prove its usefulness.<br>
>><br>
>> Cheers!<br>
>><br>
>> Siyao<br>
>> _______________________________________________<br>
>> erlang-questions mailing list<br>
>> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div>
</blockquote></div><br></body></html>