<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 5/10/20 3:27 PM, Rickard Green
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAA_Z33N_Ttk3R6DQR2EzJooG1sZ9kFO+D-w0DzGGorfA=Qs+Rw@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html;
        charset=windows-1252">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">
              <div dir="ltr">
                <div dir="ltr">On Sun, May 10, 2020 at 11:05 PM Rickard
                  Green <<a href="mailto:rickard@erlang.org"
                    moz-do-not-send="true">rickard@erlang.org</a>>
                  wrote:<br>
                </div>
                <div class="gmail_quote">
                  <blockquote class="gmail_quote" style="margin:0px 0px
                    0px 0.8ex;border-left:1px solid
                    rgb(204,204,204);padding-left:1ex">
                    <div dir="ltr">
                      <div dir="ltr">
                        <div class="gmail_quote">
                          <div dir="ltr" class="gmail_attr">On Sun, May
                            10, 2020 at 9:20 PM Guilherme Andrade <<a
                              href="mailto:g@gandrade.net"
                              target="_blank" moz-do-not-send="true">g@gandrade.net</a>>
                            wrote:<br>
                          </div>
                          <blockquote class="gmail_quote"
                            style="margin:0px 0px 0px
                            0.8ex;border-left:1px solid
                            rgb(204,204,204);padding-left:1ex">
                            <div dir="ltr">
                              <div>Hello list,</div>
                              <div><br>
                              </div>
                              <div>I've recently run into an unexpected
                                behaviour of erlcron[1] - it doesn't
                                account for any time period the computer
                                spends suspended - scheduled events get
                                delayed by equal amounts.</div>
                              <div><br>
                              </div>
                              <div>This is because it leverages
                                gen_server timeouts which, in turn, use
                                bog-standard VM timeouts, which behave
                                in the way I described. I've
                                confirmed[2] their behaviour by
                                comparing time elapsed until timeout
                                according to erlang:monotonic_time/1 vs.
                                os:system_time/1.</div>
                              <div><br>
                              </div>
                              <div>After delving into the Erlang/OTP
                                source code for a while I realized there
                                are two configuration options[3] that
                                appear to control the unexpected
                                behaviour: "<span>--enable-prefer-elapsed-monotonic-time-during-suspend"
                                  and "<span>--disable-prefer-elapsed-monotonic-time-during-suspend",
                                    introduced[4] in OTP 18.0.2.<br>
                                  </span></span></div>
                              <div><span><span><br>
                                  </span></span></div>
                              <div><span><span>The default value of the
                                    setting configured by either of
                                    those two options is "no"[5] - that
                                    is, elapsed monotonic time during
                                    suspend is not prefered.<br>
                                    <br>
                                    I would like to know the rationale
                                    for this. Is it for:</span></span></div>
                              <div><span><span>- performance reasons?
                                    (say, because it's faster and server
                                    hardware rarely suspends, if at all)<br>
                                  </span></span></div>
                              <div><span><span>- intended behaviour?
                                    (contrary to my expectations)</span></span></div>
                              <div><span><span><br>
                                  </span></span></div>
                              <div><span><span>I'd be thankful for your
                                    thoughts on this matter and whether
                                    you think the default behaviour
                                    should be changed.<br>
                                  </span></span></div>
                              <div><br>
                              </div>
                              <div>[1]: <a
                                  href="https://github.com/erlware/erlcron"
                                  target="_blank" moz-do-not-send="true">https://github.com/erlware/erlcron</a></div>
                              <div>[2]: <a
href="https://gist.github.com/g-andrade/508c779a931dde14c22c6e96319caa24"
                                  target="_blank" moz-do-not-send="true">https://gist.github.com/g-andrade/508c779a931dde14c22c6e96319caa24</a><br>
                                [3]: <a
href="http://erlang.org/documentation/doc-10.5/doc/installation_guide/INSTALL.html#configuring"
                                  target="_blank" moz-do-not-send="true">http://erlang.org/documentation/doc-10.5/doc/installation_guide/INSTALL.html#configuring</a></div>
                              <div>[4]: <a
href="https://github.com/erlang/otp/commit/4a864c1cbe16a42f3f5190881187e3c9849e985f"
                                  target="_blank" moz-do-not-send="true">https://github.com/erlang/otp/commit/4a864c1cbe16a42f3f5190881187e3c9849e985f</a></div>
                              <div>[5]: <a
href="https://github.com/erlang/otp/blob/OTP-22.3.4/erts/aclocal.m4#L2355-L2358"
                                  target="_blank" moz-do-not-send="true">https://github.com/erlang/otp/blob/OTP-22.3.4/erts/aclocal.m4#L2355-L2358<br>
                                </a></div>
                              <div>
                                <div><br>
                                  -- <br>
                                  <div dir="ltr">
                                    <div dir="ltr">
                                      <div>
                                        <div dir="ltr">
                                          <div>
                                            <div dir="ltr">Guilherme<br>
                                            </div>
                                          </div>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                          </blockquote>
                        </div>
                        <br clear="all">
                        <div>
                          <div>Yes, for performance reasons. See release
                            note from OTP 18.0.2 <<a
                              href="http://erlang.org/download/OTP-18.0.2.README"
                              target="_blank" moz-do-not-send="true">http://erlang.org/download/OTP-18.0.2.README</a>>:<br>
                            <pre>  OTP-12895    Application(s): erts

               *** POTENTIAL INCOMPATIBILITY ***

               Changed default OS monotonic clock source chosen at
               build time. This in order to improve performance. The
               behavior will now on most systems be that (both OS and
               Erlang) monotonic time stops when the system is
               suspended.

               If you prefer that monotonic time elapse during suspend
               of the machine, you can pass the command line argument
               --enable-prefer-elapsed-monotonic-time-during-suspend
               to configure when building Erlang/OTP. The
               configuration stage will try to find such a clock
               source, but might not be able to find it. Note that
               there might be a performance penalty associated with
               such a clock source.
</pre>
                            <br>
                            <br>
                          </div>
                          Regards,<br>
                        </div>
                        Rickard<br>
                        -- <br>
                        <div dir="ltr">Rickard Green, Erlang/OTP,
                          Ericsson AB</div>
                      </div>
                    </div>
                  </blockquote>
                </div>
                <br clear="all">
                <div><span><span><br>
                    </span></span></div>
                <div><span><span>I missed this part:<br>
                      <br>
                    </span></span></div>
                <div><span><span>> I'd be thankful for your thoughts
                      on this matter and whether you think the default
                      behaviour should be changed.<br>
                    </span></span></div>
                <br>
              </div>
              <div>I do *not* think the default should be changed. I
                would be very surprised if it is more than a very small
                minority of users that are interested in elapsed time
                during OS suspend. More or less everyone would have to
                take this performance penalty without any benefit. I
                don't remember any figures since this was 5 years ago,
                but I remember that the performance penalty was quite
                substantial.<br>
              </div>
              <br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    Isn't a decent use-case of the
    --enable-prefer-elapsed-monotonic-time-during-suspend configure flag
    for execution in a container, to avoid the expiration of timers
    without getting CPU time (timeouts occur too quickly, so execution
    becomes erroneous)?  With VM execution of BEAM inside, the
    clocksource can be set to kvm-clock on Linux, which avoids the
    problem but containers are unable to do that.  Has
    --enable-prefer-elapsed-monotonic-time-during-suspend been tested
    with containers (like LXC) to show more reliable operation?  I
    understand it would require the container system to be aware of the
    load on the system and play nice with the processes involved (giving
    them SIGSTOP and SIGCONT), just not sure how common that is for
    normal container operation (not manual container commands).<br>
    <br>
    Thanks,<br>
    Michael<br>
    <p><br>
    </p>
  </body>
</html>