{"id":719,"date":"2017-12-08T10:42:51","date_gmt":"2017-12-08T10:42:51","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=719"},"modified":"2017-12-08T10:42:51","modified_gmt":"2017-12-08T10:42:51","slug":"monotonicity","status":"publish","type":"page","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=719","title":{"rendered":"Monotonicity"},"content":{"rendered":"<p>The events that Orchids receives and dissects are composed of fields. \u00a0In addition to a <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">type<\/a>, each field has a <em>monotonicity<\/em> status.<\/p>\n<p>In each module page, we write\u00a0\u2713 in the `mono?&#8217; column for fields that are\u00a0<em>monotonic<\/em>. \u00a0Those are fields that can only increase (or stay the same), as new events occur. \u00a0The typical monotonic field is a time stamp or a sequence number.<\/p>\n<h3>The purpose of monotonicity<\/h3>\n<p>The monotonicity flag is used by Orchids to make a few important optimizations. \u00a0Some of them are described on the <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=357\"><code>timeout<\/code><\/a> module page. \u00a0If you write something like this in an Orchids rule:<br \/>\n<code>expect (<\/code>\u27e8what I am waiting for\u27e9<code> &amp;&amp;\u00a0<\/code>\u27e8my time field\u27e9<code>&lt;$timeout) goto<\/code>\u27e8wherever\u27e9<code>;<\/code><\/p>\n<p>where <code>$timeout<\/code> holds the final time after which we will no longer care whether\u00a0\u27e8what I am waiting for\u27e9 happened or not, and\u00a0\u27e8my time field\u27e9 is flagged as a monotonic field, then Orchids will\u00a0stop waiting after receiving the first event whose\u00a0\u27e8my time field\u27e9 field is larger than or equal to <code>$timeout<\/code>. \u00a0The way the Orchids compiler reasons is as follows: imagine Orchids receives an event whose\u00a0\u27e8my time field\u27e9 value is larger\u00a0than or equal to <code>$timeout<\/code>; then any event it will read later will have an even larger\u00a0\u27e8my time field\u27e9, and the condition of the <code>expect<\/code> transition will be false <em>forever<\/em>. \u00a0Hence it makes no sense monitoring that condition, and we can kill the corresponding thread.<\/p>\n<h3>A matter of trust<\/h3>\n<p>Orchids <em>trusts<\/em> that monotonic fields indeed only increase, but some event sources may contradict that assumption.<\/p>\n<p>If you see a monotonic field decrease, that may be the result of malevolent conduct. \u00a0That may happen in natural situations as well. \u00a0For example, if\u00a0\u27e8my time field\u27e9 reports times relative to a local time zone, and the time goes suddenly back from 3am to 2am in the middle of the night, it may be an effect of exiting <a href=\"https:\/\/en.wikipedia.org\/wiki\/Daylight_saving_time\">daylight saving time<\/a>. \u00a0The ideal cure is to have a time reporting mechanism that reports absolute values of time, not depending on a time zone or on daylight saving time, for example a Unix time count (numbers of seconds since a fixed date), or expressive and normalized time fields such as in RFC5424 <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=157\">syslog<\/a>.<\/p>\n<h3>Beyond<\/h3>\n<p>In principle, fields can also be flagged as antitonic (decreasing or staying the same), or constant (staying the same). \u00a0This is needed by the logic that Orchids uses to reason about monotonicity. \u00a0At the moment, no field is flagged as such.<\/p>\n<p>Monotonicity does not make sense for data of all types. \u00a0The order that Orchids uses is:<\/p>\n<ul>\n<li>the natural ordering on data of types <code>int<\/code>, <code>uint<\/code>, <code>float<\/code>, <code>ctime<\/code>, <code>timeval<\/code>,<\/li>\n<li>the lexicographic ordering on strings (of type <code>str<\/code>), seen as byte strings\u2014not any fancier ordering such as UTF8 collation order: that may come, but no field of type <code>str<\/code> is currently flagged as monotonic anyway;<\/li>\n<li><code>ipv4<\/code> addresses are compared as though they were unsigned 32-bit integers;<\/li>\n<li><code>ipv6<\/code> addresses are compared lexicographically, considering they are 16-byte strings;<\/li>\n<li>databases, of type <code>db[*]<\/code> or <code>db[<\/code><em>type<\/em><sub>1<\/sub><code>,<\/code> &#8230;<code>,<\/code> <em>type<sub>n<\/sub><\/em><code>]<\/code>, are compared for inclusion.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The events that Orchids receives and dissects are composed of fields. \u00a0In addition to a type, each field has a monotonicity status. In each module page, we write\u00a0\u2713 in the `mono?&#8217; column for fields that are\u00a0monotonic. \u00a0Those are fields that can only increase (or stay the same), as new events occur. \u00a0The typical monotonic field &hellip; <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=719\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Monotonicity<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-719","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=719"}],"version-history":[{"count":3,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/719\/revisions"}],"predecessor-version":[{"id":722,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/719\/revisions\/722"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}