From 8142f08ef9966c7c53e82a6097de56de260fdb06 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 14 Nov 2022 12:33:49 +0100 Subject: [PATCH] many updates --- appx/clean_for_haskell_programmers.tex | 8 +- intro/intro.tex | 124 ++++++++++++++----------- intro/iot-layers.tex | 24 ++++- other.bib | 34 ++----- preamble.tex | 2 + top/mtask_integration.tex | 4 +- top/top.tex | 51 ++++++---- tvt/tvt.tex | 18 +--- 8 files changed, 142 insertions(+), 123 deletions(-) diff --git a/appx/clean_for_haskell_programmers.tex b/appx/clean_for_haskell_programmers.tex index ff24c0e..aeba2dc 100644 --- a/appx/clean_for_haskell_programmers.tex +++ b/appx/clean_for_haskell_programmers.tex @@ -100,18 +100,18 @@ The implementation of generics in \gls{CLEAN} is very similar to that of Generic %When calling a generic function, the kind must always be specified and depending on the kind, the function may require more arguments. For example, defining a generic equality is done as in \cref{lst:generic_eq}. -\lstinputlisting[language=Clean,firstline=4,label={lst:generic_eq},caption={Generic equality function in \gls{CLEAN}.}.]{lst/generic_eq.icl} +\cleaninputlisting[firstline=4,label={lst:generic_eq},caption={Generic equality function in \gls{CLEAN}.}.]{lst/generic_eq.icl} Metadata about the types is available using the \cleaninline{of} syntax that gives the function access to metadata records, as can be seen in \cref{lst:generic_print} showing a generic print function. This abundance of metadata allows for very complex generic functions that near the expression level of template metaprogramming\ifSubfilesClassLoaded{}{ (See \cref{chp:first-class_datatypes})}. -\lstinputlisting[language=Clean,firstline=4,label={lst:generic_print},caption={Generic print function in \gls{CLEAN}.}]{lst/generic_print.icl} +\cleaninputlisting[language=Clean,firstline=4,label={lst:generic_print},caption={Generic print function in \gls{CLEAN}.}]{lst/generic_print.icl} \subsection{\texorpdfstring{\glsentrytext{GADT}}{GADT}s} \Glspl{GADT} are enriched data types that allow the type instantiation of the constructor to be explicitly defined~\citep{cheney_first-class_2003,hinze_fun_2003}. While \glspl{GADT} are not natively supported in \gls{CLEAN}, they can be simulated using embedding-projection pairs or equivalence types~\citep[\citesection{2.2}]{cheney_lightweight_2002}. To illustrate this, \cref{lst:gadt_clean} shows an example \gls{GADT} that would be implemented in \gls{HASKELL} as done in \cref{lst:gadt_haskell}\requiresGHCmod{GADTs}. -\lstinputlisting[language=Clean,firstline=4,lastline=24,label={lst:gadt_clean},caption={Expression \gls{GADT} using equivalence types in \gls{CLEAN}.}]{lst/expr_gadt.icl} -\lstinputlisting[language={[Regular]Haskell},firstline=4,label={lst:gadt_haskell},caption={Expression \gls{GADT} in \gls{HASKELL}.}]{lst/expr_gadt.hs} +\cleaninputlisting[firstline=4,lastline=24,label={lst:gadt_clean},caption={Expression \gls{GADT} using equivalence types.}]{lst/expr_gadt.icl} +\haskellinputlisting[firstline=4,label={lst:gadt_haskell},caption={Expression \gls{GADT}.}]{lst/expr_gadt.hs} \clearpage \section{Syntax} diff --git a/intro/intro.tex b/intro/intro.tex index 2444aec..6b4424f 100644 --- a/intro/intro.tex +++ b/intro/intro.tex @@ -5,28 +5,46 @@ \begin{document} \chapter{Prelude}% \label{chp:introduction} -In 2022, there were an estimated number of 13.4 billion of connected computers that sense, act or otherwise interact with people, other computers and the physical world surrounding us\footnote{\url{https://transformainsights.com/research/tam/market}, accessed on: \formatdate{13}{10}{2022}}. -The variety among these devices is considerable but these devices have one thing in common though: they are all controlled by software. -Concretely this means that programmers write code for these specific device to make sure the brains of the device---the processor---do what we want it to do. +\begin{chapterabstract} + This chapter introduces the contents of the thesis and a reading guide. + Furthermore, it provides background material on \glsxtrlong{IOT}, \glsxtrlongpl{DSL}, and \glsxtrlong{TOP}; and a detailed overview of the contributions. +\end{chapterabstract} + +There are at least 13.4 billion computers connected to the internet at the time of writing\footnote{\url{https://transformainsights.com/research/tam/market}, accessed on: \formatdate{13}{10}{2022}}. +These devices sense, act, or otherwise interact with people, other computers, and the world surrounding us. +Notwithstanding the substantial variety among these devices, they have one thing in common: they are all require software to operate. An increasing amount of these connected devices are so-called \emph{edge devices} that operate in the \gls{IOT}. -Typically these edge devices are small microprocessors containing various sensors and actuators to interact with the physical world. -They are often part of and coordinated by a bigger system called \gls{IOT} systems. -The variety among the edge devices and the fact that they differ substantially from other devices makes it complex to program \gls{IOT} systems. - -%These ed -%These edge devices differ very much from other devices we see around us. -%Compared to servers, laptops, tablets, or mobile phones they boast tiny amounts of memory, are powered by a slow but energy efficient microprocessor, only support low-level programming languages, and are not so easily reprogrammed. -%Moreover, these edge devices differ among eachother as well by using various microprocessor architectures, different communication protocols and using a variety of device-specific toolchains. -%As a result, there are many points of failure and programming these systems is difficult and error-prone. -% -%\Gls{TOP} is a novel programming paradigm that offers a solution to this problem. -%In a \gls{TOP} language, from a single declarative specification of the work that needs to be done, ready-for-work applications are generated for all layers of the system. -%However, the hardware requirements for traditional \gls{TOP} frameworks make it not feasable to run these generated applications on resource-constrained edge devices. -% -%\Glspl{DSL} can overcome this limitation because domain-specific knowledge is built into the programming language, allowing for lower hardware requirements. -%This thesis presents \gls{MTASK}, a \gls{TOP} \gls{DSL} for edge devices that can be fully integrated with \gls{ITASK}, a \gls{TOP} \gls{DSL} for distributed multi-user workflow systems. -%With \gls{MTASK}, all layers of an \gls{IOT} system can be programmed from a single programming language in a single programming paradigm. +Typically these edge devices are small microprocessors containing sensors and actuators to interact with the physical world. +The variety within edge devices, and the fact that they differ substantially from other types of devices, makes it complex to program \gls{IOT} systems.\todo{make sentence logical} +Hence, an \gls{IOT} programmer has to program each device and their interoperation using different programming paradigms, programming languages, and abstraction levels resulting in semantic friction. + +This thesis introduces research on the many aspects of orchestrating \gls{IOT} systems using \gls{TOP}. +\Gls{TOP} is a novel programming paradigm for programming multi-tier workflow systems using a single declarative specification of the work that needs to be done. +Using advanced compiler technologies, much of the internals and communication of multi-tier applications are automatically generated and the result of compilation is a ready-for-work application. +Unfortunately, because the abstraction level is so high, the hardware requirements are too excessive to be suitable for the average edge device. + +This is where \glspl{DSL} come into play. +\Glspl{DSL} are languages created with a specific domain in mind. +Consequently, domain knowledge does not have to be expressed in the language itself but they can be built-in features, thus drastically reducing the hardware requirements even with high levels of abstraction. + +\section{Reading guide} +On Wikipedia, a musical rhapsody is defined as follows \citep{wikipedia_contributors_rhapsody_2022}: +\begin{quote}\emph{% + A \emph{rhapsody} in music is a one-movement work that is episodic yet integrated, free-flowing in structure, featuring a range of highly contrasted moods, colour, and tonality.} +\end{quote} +This thesis is structured as a pure functional rhapsody containing three episodes barded by the introduction and conclusion (\cref{chp:introduction,chp:conclusion}). +\Cref{prt:dsl} is a paper-based---otherwise known as cumulative---episode providing insight in advanced \gls{DSL} embedding techniques. +The chapters are readable independently. +\Cref{prt:top} is a monograph showing \gls{MTASK}, a \gls{TOP} \gls{DSL} for the \gls{IOT}. +Hence, the chapters are best read in order. +\Cref{prt:tvt} is a journal article in which quantitative and qualitatively compares traditional tiered \gls{IOT} programming to tierless programming. +The chapter is readable independently. + +The following sections provide background material on the \gls{IOT}, \glspl{DSL}, and \gls{TOP} after which a detailed overview of the contributions is presented. +Text typeset as \texttt{teletype} represents source code. +Standalone source code listings are used are marked with the programming language used. +For the \gls{FP} language \gls{CLEAN}, a guide tailored to \gls{HASKELL} programmers is available as in \cref{chp:clean_for_haskell_programmers}. \section{Internet of things}\label{sec:back_iot} The \gls{IOT} is growing rapidly and it is changing the way people and machines interact with the world. @@ -36,41 +54,42 @@ While the term \gls{IOT} briefly gained interest around 1999 to describe the com \emph{The \glsxtrlong{IOT}, or \glsxtrshort{IOT}, is the integration of people, processes and technology with connectable devices and sensors to enable remote monitoring, status, manipulation and evaluation of trends of such devices.} \end{quote} -CISCO states that the \gls{IOT} only started when there where as many connected devices as there were people on the globe, i.e.\ around 2008 \citep{evans_internet_2011}. -Today, the \gls{IOT} is the term for a system of devices that sense the environment, act upon it and communicate with each other and the world. +CISCO states that the \gls{IOT} started when there where as many connected devices as there were people on the globe, i.e.\ around 2008 \citep{evans_internet_2011}. +Today, \gls{IOT} is the term for a system of devices that sense the environment, act upon it and communicate with each other and the world. These connected devices are already in households all around us in the form of smart electricity meters, fridges, phones, watches, home automation, \etc. When describing \gls{IOT} systems, a tiered---or layered---architecture is often used to compartmentalize the technology. -The number of tiers heavily depends on the required complexity of the model but for the intents and purposes of the thesis, the four layer architecture shown in \cref{fig:iot-layers} is used. +The number of tiers heavily depends on the required complexity of the model but for the intents and purposes of this thesis, the four layer architecture as shown in \cref{fig:iot-layers} is used. \begin{figure}[ht] \centering \includestandalone{iot-layers} - \caption{A four-layer \gls{IOT} architecture.}% + \caption{A four-tier \gls{IOT} architecture.}% \label{fig:iot-layers} \end{figure} -Closest to the end-user is the presentation layer, it provides the interface between the user and the \gls{IOT} application. -In home automation this may be a web interface or a app used on a phone or mounted tablet to interact with the edge devices and view the sensor data. +To explain the tiers, an example \gls{IOT} application---home automation---is dissected accordingly. +Closest to the end-user is the presentation layer, it provides the interface between the user and the \gls{IOT} system. +In home automation this may be a web interface or an app used on a phone or mounted tablet to interact with the edge devices and view the sensor data. -The application layer provides the \glspl{API}, interfaces and data storage. -A cloud service or local server provides this layer in a typical home automation application. +The application layer provides the \glspl{API}, data interfaces, and data storage of the \gls{IOT} system. +A cloud server or local server provides this layer in a typical home automation application. All layers are connected using the network layer. In many applications this is implemented using conventional networking techniques such as WiFi or Ethernet. -However, networks or layers on top of it tailored to the needs of \gls{IOT} applications have been increasingly popular such as \gls{BLE}, LoRa, ZigBee, LTE-M, or \gls{MQTT}. +However, networks or layers on top of it---tailored to the needs of \gls{IOT} systems---have been increasingly popular such as \gls{BLE}, LoRa, ZigBee, LTE-M, or \gls{MQTT}. The perception layer---also called edge layer---collects the data and interacts with the environment. It consists of edge devices such as microprocessors equipped with various sensors and actuators. -In home automation this layer consists of all the devices hosting the sensors and actuators such as in a smart lightbulb, an actuator to open a door or a temperature and humidity sensor. +In home automation this layer consists of all the devices hosting the sensors and actuators such as a smart lightbulb, an actuator to open a door or a temperature and humidity sensor. Across the layers, the devices are a large heterogeneous collection of different platforms, protocols, paradigms, and programming languages often resulting in impedance problems or semantic friction between layers when programming \citep{ireland_classification_2009}. -Even more so, perception layer specifically often is a heterogeneous collections of microprocessors in itself as well, each having their own peculiarities, language of choice and hardware interfaces. +Even more so, perception layer itself often is a heterogeneous collections of microprocessors in itself as well, each having their own peculiarities, language of choice, and hardware interfaces. As the edge hardware needs to be cheap, small-scale, and energy efficient, the microprocessors used to power these devices do not have a lot of computational power, only a soup\c{c}on of memory, and little communication bandwidth. -Typically the devices do not run a full fledged \gls{OS} but a compiled firmware. -This firmware is often written in an imperative language that needs to be flashed to the program memory. -Program memory typically is flash based and only lasts a couple of thousand writes before it wears out. +Typically the devices do not run a full fledged \gls{OS} but a compiled firmware that written in an imperative language. While devices are getting a bit faster, smaller, and cheaper, they keep these properties to an extent, greatly reducing the flexibility for dynamic systems where tasks are created on the fly, executed on demand, or require parallel execution. +As program memory is mostly flash based and only lasts a couple of thousand writes before it wears out, it is not suitable for rapid reconfiguring and reprogramming. + These problems can be mitigated by dynamically sending code to be interpreted to the microprocessor. With interpretation, a specialized interpreter is flashed in the program memory once that receives the program code to execute at runtime. Interpretation always comes with an overhead, making it challenging to create them for small edge devices. @@ -81,7 +100,8 @@ However, the hardware requirements can be reduced by embedding domain-specific d Programming languages can be divided up into two categories: \glspl{DSL}\footnote{Historically this has been called DSEL as well.} and \glspl{GPL} \citep{fowler_domain_2010}. Where \glspl{GPL} are not made with a demarcated area in mind, \glspl{DSL} are tailor-made for a specific domain. Writing idiomatic domain-specific code in an \gls{DSL} is easy but this may come at the cost of the \gls{DSL} being less expressive to an extent that it may not even be Turing complete. -\Glspl{DSL} come in two main flavours: standalone and embedded\footnote{Also called external and internal respectively.} of which \glspl{EDSL} can again be classified into heterogeneous and homogeneous languages (see \cref{fig:hyponymy_of_dsls} for this hyponymy). +\Glspl{DSL} come in two main flavours: standalone and embedded (\cref{sec:standalone_embedded})\footnote{Also called external and internal respectively.} of which \glspl{EDSL} can again be classified into heterogeneous and homogeneous languages (\cref{sec:hetero_homo}). +This hyponymy is shown in \cref{fig:hyponymy_of_dsls}. \begin{figure}[ht] \centering @@ -90,7 +110,7 @@ Writing idiomatic domain-specific code in an \gls{DSL} is easy but this may come \label{fig:hyponymy_of_dsls} \end{figure} -\subsection{Standalone and embedded} +\subsection{Standalone and embedded}\label{sec:standalone_embedded} \glspl{DSL} where historically created as standalone languages, meaning all the machinery is developed solely for the language. The advantage of this approach is that the language designer is free to define the syntax and type system of the language as they wish, not being restricted by any constraint. Unfortunately it also means that they need to develop a compiler or interpreter for the language to be usable making standalone \glspl{DSL} costly to create. @@ -104,7 +124,7 @@ If the syntax of the host language is not very flexible, the syntax of the \gls{ Furthermore, errors shown to the programmer may be larded with host language errors, making it difficult for a non-expert of the host language to work with the \gls{DSL}. Pure \gls{FP} languages are especially suitable for hosting embedded \glspl{DSL} because they have strong and versatile type systems, minimal but flexible syntax and offer referential transparency. -\subsection{Heterogeneity and homogeneity} +\subsection{Heterogeneity and homogeneity}\label{sec:hetero_homo} \Citet{tratt_domain_2008} applied a notion from metaprogramming \citep{sheard_accomplishments_2001} to \glspl{EDSL} to define homogeneity and heterogeneity of \glspl{EDSL} as follows: \begin{quote} @@ -125,7 +145,7 @@ In fact, \gls{ITASK} and \gls{MTASK} are both heterogeneous \glspl{EDSL} and \gl \section{\texorpdfstring{\Glsxtrlong{TOP}}{Task-oriented programming}}\label{sec:back_top} \Gls{TOP} is a declarative programming paradigm designed to model interactive systems \citep{plasmeijer_task-oriented_2012}. \Citet{steenvoorden_tophat_2022} defines two instruments for \gls{TOP}: \gls{TOP} languages and \gls{TOP} engines. -A \gls{TOP} language is the formal language to specify workflows. +A \gls{TOP} language is a language to specify workflows.\todo{improve sentence} A \gls{TOP} engine executes such a specification as a ready-for-work application. Instead of dividing problems into layers or tiers, as is done in \gls{IOT} architectures, it deals with separation of concerns in a novel way. From the data types, utilising various \emph{type-parametrised} concepts, all other aspects are handled automatically (see \cref{fig:tosd}). @@ -147,6 +167,7 @@ This approach to software development is called \gls{TOSD} \citep{wang_maintaini \label{fig:tosd} \end{figure} +\todo{describe relation with \gls{IOT} architecture} \begin{description} \item[\Glsxtrshort{UI} (presentation layer):] The \gls{UI} of the system is automatically generated from the representation of the type. @@ -167,7 +188,6 @@ This approach to software development is called \gls{TOSD} \citep{wang_maintaini The \gls{UOD} from the business layer is explicitly and separately modelled by the relations that exist in the functions of the host language. \end{description} - \subsection{\texorpdfstring{\Gls{ITASK}}{ITask}} The concept of \gls{TOP} originated from the \gls{ITASK} framework, a declarative workflow language and \gls{TOP} engine for defining multi-user distributed web applications implemented as an \gls{EDSL} in the lazy pure \gls{FP} language \gls{CLEAN} \citep{plasmeijer_itasks:_2007,plasmeijer_task-oriented_2012}. From the structural properties of the data types, the entire user interface is automatically generated. @@ -198,26 +218,24 @@ enterPerson >>! \result->Hint "You Entered:" @>> viewInformation [] result[+\label{lst:task_comb}+] \end{lstClean} -\subsection{Other \texorpdfstring{\glsxtrshort{TOP}}{TOP} languages} -While \gls{ITASK} conceived \gls{TOP}, it is not the only \gls{TOP} language and engine. -Some \gls{TOP} languages and systems arose from Master's and Bachelor's thesis projects (e.g.\ \textmu{}Task \citep{piers_task-oriented_2016} and LTasks \citep{van_gemert_task_2022}) or were created to solve a practical problem (e.g.\ Toppyt \citep{lijnse_toppyt_2022} and hTask \citep{lubbers_htask_2022}). -Furthermore, \gls{TOPHAT} is a fully formally specified \gls{TOP} language designed to capture the essence of \gls{TOP} formally \citep{steenvoorden_tophat_2019}. -It is also possible to translate \gls{TOPHAT} code to \gls{ITASK} to piggyback on the \gls{TOP} engine it offers. - \subsection{\texorpdfstring{\Gls{MTASK}}{MTask}} This thesis uses a novel \gls{TOP} language designed for defining workflows for \gls{IOT} edge devices \citep{koopman_task-based_2018}. It is written in \gls{CLEAN} as a multi-view \gls{EDSL} and hence there are multiple interpretations of the language of which the byte code compiler is the most relevant for this thesis. From the terms in the \gls{TOP} language, a very compact binary representation of the work that needs to be done is compiled. This specification is then sent to a device that runs the \gls{MTASK} \gls{RTS}, a domain-specific \gls{TOP} engine implemented as a feather-light domain-specific \gls{OS}. -\Gls{MTASK} is seemlessly integrated with \gls{ITASK}, it allows the programmer to define all layers of an \gls{IOT} system from a single declarative specification. +\Gls{MTASK} is seamlessly integrated with \gls{ITASK}, it allows the programmer to define all layers of an \gls{IOT} system from a single declarative specification. -\section{Reading guide and contributions}\label{sec:contributions} -This novel view on programming \gls{IOT} systems is presented in the thesis as a purely functional rhapsody in three episodes. -On Wikipedia, a rhapsody is defined as follows \citep{wikipedia_contributors_rhapsody_2022}: -\begin{quote} - \emph{A \emph{rhapsody} in music is a one-movement work that is episodic yet integrated, free-flowing in structure, featuring a range of highly contrasted moods, colour, and tonality. - An air of spontaneous inspiration and a sense of improvisation make it freer in form than a set of variations.} -\end{quote} +\todo[inline]{Example application here, e.g.\ blink?} + + +\subsection{Other \texorpdfstring{\glsxtrshort{TOP}}{TOP} languages} +While \gls{ITASK} conceived \gls{TOP}, it is not the only \gls{TOP} language and engine. +Some \gls{TOP} languages and systems arose from Master's and Bachelor's thesis projects (e.g.\ \textmu{}Task \citep{piers_task-oriented_2016} and LTasks \citep{van_gemert_task_2022}) or were created to solve a practical problem (e.g.\ Toppyt \citep{lijnse_toppyt_2022} and hTask \citep{lubbers_htask_2022}). +Furthermore, \gls{TOPHAT} is a fully formally specified \gls{TOP} language designed to capture the essence of \gls{TOP} formally \citep{steenvoorden_tophat_2019}. +It is also possible to translate \gls{TOPHAT} code to \gls{ITASK} to piggyback on the \gls{TOP} engine it offers \citep[\citesection{G.3}]{steenvoorden_tophat_2022}. + +\section{Contributions}\label{sec:contributions} +This section provides a thorough overview of the relation to publications and the scientific contributions of the episodes and chapters. \subsection{\nameref{prt:dsl}} The \gls{MTASK} system is a heterogeneous \gls{EDSL} and during the development of it, several novel basal techniques for embedding \glspl{DSL} in \gls{FP} languages have been found. diff --git a/intro/iot-layers.tex b/intro/iot-layers.tex index b2f5852..06298c0 100644 --- a/intro/iot-layers.tex +++ b/intro/iot-layers.tex @@ -1,17 +1,31 @@ \documentclass[tikz]{standalone} \usetikzlibrary{positioning} \begin{document} -\begin{tikzpicture}[node distance=1em,nodes={rectangle,draw,minimum width=10em}] +\begin{tikzpicture}[node distance=3em,nodes={rectangle,draw,minimum width=12em}] % \node (0) [dotted] {Business layer}; % \node (1) [below=of 0] {Presentation layer}; \node (1) [] {Presentation layer}; \node (2) [below=of 1] {Application layer}; - \node (3) [below=of 2] {Network layer}; - \node (4) [below=of 3] {Perception layer}; +% \node (3) [below=of 2] {Network layer}; + \node (3) [below=of 2] {Perception layer}; -% \draw [<->] (0) -- (1); \draw [<->] (1) -- (2); \draw [<->] (2) -- (3); - \draw [<->] (3) -- (4); + + \draw [fill=white] + ([xshift=1em,yshift=-2em]1.south west) + -- ([xshift=1em,yshift=-1em]1.south west) + -- ([yshift=-1em,xshift=1em]1.south east) + -- ([xshift=1em]1.north east) + -- ([xshift=3em]1.north east) + -- node [draw=none,midway,sloped,below,yshift=-2pt] {Network layer} ([xshift=3em]3.south east) + -- ([xshift=1em]3.south east) + -- ([yshift=1em,xshift=1em]3.north east) + -- ([xshift=1em,yshift=1em]3.north west) + -- ([xshift=1em,yshift=2em]3.north west) + -- ([yshift=2em,xshift=1em]3.north east) + -- ([yshift=-2em,xshift=1em]1.south east) + -- cycle; + ; \end{tikzpicture} \end{document} diff --git a/other.bib b/other.bib index e798083..2f2daad 100644 --- a/other.bib +++ b/other.bib @@ -354,20 +354,6 @@ Publisher: Association for Computing Machinery}, file = {Gibbons - 2015 - Functional Programming for Domain-Specific Languag.pdf:/home/mrl/.local/share/zotero/storage/ARUBLFU6/Gibbons - 2015 - Functional Programming for Domain-Specific Languag.pdf:application/pdf}, } -@incollection{lubbers_writing_2019, - address = {Cham}, - title = {Writing {Internet} of {Things} applications with {Task} {Oriented} {Programming}}, - abstract = {The Internet of Things (IOT) is growing fast. In 2018, there was approximately one connected device per person on earth and the number has been growing ever since. The devices interact with the environment via different modalities at the same time using sensors and actuators making the programs parallel. Yet, writing this type of programs is difficult because the devices have little computation power and memory, the platforms are heterogeneous and the languages are low level. Task Oriented Programming (TOP) is a novel declarative programming language paradigm that is used to express coordination of work, collaboration of users and systems, the distribution of shared data and the human computer interaction. The mTask language is a specialized, yet full-fledged, multi-backend TOP language for IOT devices. With the bytecode interpretation backend and the integration with iTasks, tasks can be executed on the device dynamically. This means that —according to the current state of affairs— tasks can be tailor-made at run time, compiled to device-agnostic bytecode and shipped to the device for interpretation. Tasks sent to the device are fully integrated in iTasks to allow every form of interaction with the tasks such as observation of the task value and interaction with Shared Data Sources (SDSs). The application is —server and devices— are programmed in a single language, albeit using two embedded Domain Specific Languages (EDSLs).}, - language = {en}, - booktitle = {Central {European} {Functional} {Programming} {School}: 8th {Summer} {School}, {CEFP} 2019, {Budapest}, {Hungary}, {July} 17–21, 2019, {Revised} {Selected} {Papers}}, - publisher = {Springer International Publishing}, - author = {Lubbers, Mart and Koopman, Pieter and Plasmeijer, Rinus}, - year = {2019}, - note = {in-press}, - pages = {51}, - file = {cefp.pdf:/home/mrl/.local/share/zotero/storage/VEWFI5DG/cefp.pdf:application/pdf}, -} - @mastersthesis{veen_van_der_mutable_2020, address = {Nijmegen}, title = {Mutable {Collection} {Types} in {Shallow} {Embedded} {DSLs}}, @@ -1198,18 +1184,6 @@ Publisher: Association for Computing Machinery}, file = {Leijen and Meijer - 2000 - Domain Specific Embedded Compilers.pdf:/home/mrl/.local/share/zotero/storage/YHPF2VZ6/Leijen and Meijer - 2000 - Domain Specific Embedded Compilers.pdf:application/pdf}, } -@incollection{koopman_simulation_2018, - address = {Cham}, - title = {Simulation of a {Task}-{Based} {Embedded} {Domain} {Specific} {Language} for the {Internet} of {Things}}, - language = {en}, - booktitle = {Central {European} {Functional} {Programming} {School}: 7th {Summer} {School}, {CEFP} 2018, {Košice}, {Slovakia}, {January} 22–26, 2018, {Revised} {Selected} {Papers}}, - publisher = {Springer International Publishing}, - author = {Koopman, Pieter and Lubbers, Mart and Plasmeijer, Rinus}, - year = {2018}, - note = {in-press}, - pages = {51}, -} - @techreport{plasmeijer_clean_2021, address = {Nijmegen}, title = {Clean {Language} {Report} version 3.1}, @@ -1825,3 +1799,11 @@ Publisher: Association for Computing Machinery}, pages = {34}, file = {Sun and Dhandhania - Compositional Embeddings of Domain-Specific Langua.pdf:/home/mrl/.local/share/zotero/storage/Y4GADQFP/Sun and Dhandhania - Compositional Embeddings of Domain-Specific Langua.pdf:application/pdf}, } + +@misc{lubbers_htask_2022, + title = {{hTask}}, + url = {https://gitlab.com/mlubbers/acsds}, + urldate = {2022-10-07}, + author = {Lubbers, Mart}, + year = {2022}, +} diff --git a/preamble.tex b/preamble.tex index 99a0c94..6625618 100644 --- a/preamble.tex +++ b/preamble.tex @@ -206,7 +206,9 @@ \newcommand{\arduinoinline}[1]{\lstinline[language={[Arduino]C++},postbreak=]|#1|} \newcommand{\pythoninline}[1]{\lstinline[language=Python,postbreak=]|#1|} \newcommand{\cleaninline}[1]{\lstinline[language=Clean,postbreak=]|#1|} +\newcommand{\cleaninputlisting}[2][]{\renewcommand*{\lstlistingname}{Listing (\gls{CLEAN})}\lstinputlisting[language=Clean,#1]{#2}} \newcommand{\haskellinline}[1]{\lstinline[language={[Regular]Haskell},postbreak=]|#1|} +\newcommand{\haskellinputlisting}[2][]{\renewcommand*{\lstlistingname}{Listing (\gls{HASKELL})}\lstinputlisting[language={[Regular]Haskell},#1]{#2}} \newcommand{\haskelllhstexinline}[1]{\lstinline[language={[Lhs2Tex]Haskell},postbreak=]|#1|} %For storing listings in footnotes \newsavebox{\LstBox} diff --git a/top/mtask_integration.tex b/top/mtask_integration.tex index f1f5e89..a952224 100644 --- a/top/mtask_integration.tex +++ b/top/mtask_integration.tex @@ -13,7 +13,7 @@ \node (CN) [client,inner sep=0pt,draw,right=of CD] {Client\textsubscript{n}}; % line between server and browser - \draw [dotted] ([xshift=-7em,yshift=-.8em]C1.south west) node[left,above]{browser} node[left,below]{server(s)} -- ([xshift=5em,yshift=-.8em]CN.south east); + \draw [dotted] ([xshift=-5em,yshift=-.8em]C1.south west) node[left,above]{browser} node[left,below]{server(s)} -- ([xshift=5em,yshift=-.8em]CN.south east); \node[task,inner sep=-4.5pt,below=of C1,fill=white,xshift=6.5em,yshift=-4.5em] (Tn) {Task\textsubscript{n}}; \node[task,inner sep=-4.5pt,below=of C1,fill=white,xshift=5em,yshift=-3.0em] (Td) {\ldots}; @@ -28,7 +28,7 @@ \node[fit={(T1)(Sn)},draw] (TS) {}; % line between client and server - \draw [dotted] ([xshift=-7em,yshift=-11em]C1.south west) node[left,above]{server(s)} node[left,below]{device(s)} -- ([xshift=5em,yshift=-11em]CN.south east); + \draw [dotted] ([xshift=-5em,yshift=-11em]C1.south west) node[left,above]{server(s)} node[left,below]{device(s)} -- ([xshift=5em,yshift=-11em]CN.south east); % device 1 \node[task,text width=1.5em,inner sep=-4.5pt,node distance=12em,below=of C1,double copy shadow={shadow xshift=.4em,shadow yshift=-.4em},fill=white] (D1T1) {}; diff --git a/top/top.tex b/top/top.tex index 3f18e5a..d777559 100644 --- a/top/top.tex +++ b/top/top.tex @@ -7,11 +7,12 @@ \pagenumbering{arabic} }{} -\chapter{Introduction to \texorpdfstring{\glsxtrshort{IOT}}{IoT} device programming}% +\chapter{Edge device programming}% \label{chp:top4iot} \todo{betere chapter naam} \begin{chapterabstract} This chapter introduces \gls{MTASK} and puts it into perspective compared to traditional microprocessor programming. + It does so by showing how to program microprocessors using \gls{ARDUINO}, a popular microprocessor framework, and the equivalent \gls{MTASK} programs. \end{chapterabstract} The edge layer of \gls{IOT} system mostly consists of microprocessors that require a different method of programming. @@ -682,26 +683,22 @@ task = declarePin D3 PMInput \d3-> In {main=count d3 .||. count d5} \end{lstClean} -\chapter{Green computing with \texorpdfstring{\gls{MTASK}}{mTask}}% -\label{chp:green_computing_mtask} - -\section{Green \texorpdfstring{\glsxtrshort{IOT}}{IoT} computing} - -\section{Task scheduling} -\subsection{Language} -\subsection{Device} - -\section{Interrupts} - \chapter{Integration with \texorpdfstring{\gls{ITASK}}{iTask}}% \label{chp:integration_with_itask} +\begin{chapterabstract} + This chapter shows the integration with \gls{ITASK}. + It gives an intuition for the architecture of the \gls{IOT} systems. + The interface for connecting devices, lifting \gls{MTASK} tasks to \gls{ITASK} tasks and lifting \gls{ITASK} \glspl{SDS} to \gls{MTASK} \glspl{SDS} is shown. +\end{chapterabstract} + The \gls{MTASK} language is a multi-view \gls{DSL}, i.e.\ there are multiple interpretations possible for a single \gls{MTASK} term. -Using the byte code compiler (\cleaninline{BCInterpret}) \gls{DSL} interpretation, \gls{MTASK} tasks are fully integrated in \gls{ITASK} and executed as if they were regular \gls{ITASK} tasks and communicate using \gls{ITASK} \glspl{SDS}. -\Gls{MTASK} devices contain a domain-specific \gls{OS} (\gls{RTS}) and are little \gls{TOP} servers in their own respect, being able to execute tasks. +Using the byte code compiler (\cleaninline{BCInterpret}) \gls{DSL} interpretation, \gls{MTASK} tasks can be fully integrated in \gls{ITASK}. +They are executed as if they are regular \gls{ITASK} tasks and they communicate may access \glspl{SDS} from \gls{ITASK} as well. +\Gls{MTASK} devices contain a domain-specific \gls{OS} (\gls{RTS}) and are little \gls{TOP} engines in their own respect, being able to execute tasks. \Cref{fig:mtask_integration} shows the architectural layout of a typical \gls{IOT} system created with \gls{ITASK} and \gls{MTASK}. The entire system is written as a single \gls{CLEAN} specification where multiple tasks are executed at the same time. Tasks can access \glspl{SDS} according to many-to-many communication and multiple clients can work on the same task. -Devices are integrated into the system using the \cleaninline{widthDevice} function (see \cref{sec:withdevice}). +Devices are integrated into the system using the \cleaninline{withDevice} function (see \cref{sec:withdevice}). Using \cleaninline{liftmTask}, \gls{MTASK} tasks are lifted to a device (see \cref{sec:liftmtask}). \Gls{ITASK} \glspl{SDS} are lifted to the \gls{MTASK} device using \cleaninline{liftsds} (see \cref{sec:liftmtask}). @@ -713,7 +710,8 @@ Using \cleaninline{liftmTask}, \gls{MTASK} tasks are lifted to a device (see \cr \end{figure} \section{Devices}\label{sec:withdevice} -\Gls{MTASK} tasks in the byte code compiler view are always executed on a certain device. +When interpreted by the byte code compiler view, an \gls{MTASK} task produces a compiler. +This compiler is exceuted at run time so that the resulting byte code can be sent to an edge device. All communication with this device happens through a so-called \emph{channels} \gls{SDS}. The channels contain three fields, a queue of messages that are received, a queue of messages to send and a stop flag. Every communication method that implements the \cleaninline{channelSync} class can provide the communication with an \gls{MTASK} device. @@ -746,10 +744,31 @@ class liftsds v where \chapter{Implementation}% \label{chp:implementation} +\begin{chapterabstract} + This chapter shows the implementation of the \gls{MTASK} system. + It is threefold: first it shows the implementation of the byte code compiler for \gls{MTASK}'s \gls{TOP} language, then is details of the implementation of \gls{MTASK}'s \gls{TOP} engine that executes the \gls{MTASK} tasks on the microprocessor, and finally it shows how the integration of \gls{MTASK} tasks and \glspl{SDS} is implemented both on the server and on the device. +\end{chapterabstract} IFL19 paper, bytecode instructieset~\cref{chp:bytecode_instruction_set} \section{Integration with \texorpdfstring{\gls{ITASK}}{iTask}} IFL18 paper stukken +\chapter{Green computing with \texorpdfstring{\gls{MTASK}}{mTask}}% +\label{chp:green_computing_mtask} +\begin{chapterabstract} + This chapter demonstrate the energy saving features of \gls{MTASK}. + First it gives an overview of general green computing measures for edge devices. + Then \gls{MTASK}'s task scheduling is explained and it is shown how to customise it so suit the applications and energy needs. + Finally it shows how to use interrupts in \gls{MTASK} to reduce the need for polling. +\end{chapterabstract} + +\section{Green \texorpdfstring{\glsxtrshort{IOT}}{IoT} computing} + +\section{Task scheduling} +\subsection{Language} +\subsection{Device} + +\section{Interrupts} + \input{subfilepostamble} \end{document} diff --git a/tvt/tvt.tex b/tvt/tvt.tex index 39d0c23..79c3f4e 100644 --- a/tvt/tvt.tex +++ b/tvt/tvt.tex @@ -111,12 +111,10 @@ Both web and \gls{IOT} applications are commonly structured into tiers, e.g.\ th \begin{figure} \includegraphics[width=.95\linewidth]{arch} \caption{% - \begin{sloppypar} \Gls{PRS} and \gls{PWS} (left) together with \gls{CRS} and \gls{PRS} (right) mapped to the four-tier \gls{IOT} architecture. Every box is the diagram denotes a source file or base. Bold blue text describes the language or technology used in that source. The network and perception layer are unique to the specific implementation, where the application and presentation layers are shared between implementations. - \end{sloppypar} }% \label{fig_t4t:iot_arch} \end{figure} @@ -156,7 +154,6 @@ Web of Things aims to facilitate re-use by providing standardised metadata and o \label{sec_t4t:TiredvsTierless} A radical approach to overcoming the challenges raised by tiered distributed software is to use a tierless programming language that eliminates the semantic friction between tiers by generating code for all tiers, and all communication between tiers, from a single program. -%\adriancomment{Also referred to as multi-tier programming, tierless language applications usually utilise a single language, paradigm and type system, and the entire system is simultaneously checked by the compiler \citep{weisenburger2020survey}.} Typically a tierless program uses a single language, paradigm and type system, and the entire distributed system is simultaneously checked by the compiler. There is intense interest in developing tierless, or multitier, language technologies with a number of research languages developed over the last fifteen years, e.g.\ \citep{cooper2006links, serrano2006hop, troyer_building_2018, 10.1145/2775050.2633367}. These languages demonstrate the @@ -250,7 +247,6 @@ Tierless languages may adopt a range of communication paradigms for communicatin \Gls{CLEAN}\slash\gls{ITASK}/\gls{MTASK} and \gls{CLEAN}/\gls{ITASK} communicate using a combination of remote task invocation, similar to remote procedures, and shared state through \glspl{SDS}. \Cref{lst_t4t:itaskTempFull} illustrates: \cref{lst_t4t:itaskTempFull:startdevtask} shows a server task launching a remote task, \cleaninline{devTask}, on to a sensor node; and \cref{lst_t4t:itaskTempFull:remoteShare} shows the sharing of the remote \cleaninline{latestTemp} \gls{SDS}. -%\mlcomment{I think this is fine} %\subsubsection{Placement} % @@ -693,7 +689,6 @@ To ensure that the comparison reported in the following sections is based on \gl \label{sec_t4t:Validation} The main goal of the \gls{UOG} smart campus project is to provide a testbed for sensor nodes and potentially other devices to act as a data collection and computation platform for the \gls{UOG} smart campus. The high-level functional requirements, as specified by the \gls{UOG} smart campus project board, are as follows. The system should: -%\mlcomment{can be inline as well} \begin{enumerate} \item be able to measure temperature and humidity as well as light intensity, @@ -719,7 +714,6 @@ All four smart campus implementations meet these high-level requirements. Observation of the four implementations shows that they operate as expected, e.g.\ detecting light or motion. To illustrate \cref{fig_t4t:webinterfaces} shows the web interface for the implementations where \gls{CWS} and \gls{CRS} are deployed in a different room from \gls{PWS} and \gls{PRS}. All four implementations use an identical set of inexpensive sensors, so we expect the accuracy of the data collected is within tolerance levels. This is validated by comparing \gls{PRS} and \gls{PWS} sensor nodes deployed in the same room for some minutes. The measurements show only small variances, e.g.\ temperatures recorded differ by less than \qty{0.4}{\celcius}, and light by less than \qty{1}{lux}. For this room monitoring application precise timings are not critical, and we don't compare the timing behaviours of the implementations. -%\adriancomment{Maybe include a reference for accepted standards of variation between the same type of sensors?} % Phil: lets see what the reviewers say @@ -750,14 +744,11 @@ In \gls{PWS}, the hand-written \gls{MICROPYTHON} is compiled to byte code for ex The smart campus sensor node programs executing on the Raspberry Pis have far higher maximum residencies than those executing on the microprocessors: \qty{3.5}{\mebi\byte} for \gls{PRS} and \qty{2.7}{\mebi\byte} for \gls{CRS}. In \gls{CRS} the sensor node code is a set of \gls{ITASK} executing on a full-fledged \gls{ITASK} server running in distributed child mode and this consumes far more memory. %The memory used is actually very similar to the memory usage of the server with a single client connected. In \gls{PRS} the sensor node program is written in \gls{PYTHON}, a language far less focused on minimising memory usage than \gls{MICROPYTHON}. For example an object like a string is larger in \gls{PYTHON} than in \gls{MICROPYTHON} and consequently does not support all features such as \emph{f-strings}. -Furthermore, not all advanced \gls{PYTHON} feature regarding classes are available in \gls{MICROPYTHON}, i.e.\ only a subset of the \gls{PYTHON} specification is supported \citep{diffmicro}.%\mlcomment{reference \url{https://docs.micropython.org/en/latest/genrst/index.html} ? It contains an overview of supported features} +Furthermore, not all advanced \gls{PYTHON} feature regarding classes are available in \gls{MICROPYTHON}, i.e.\ only a subset of the \gls{PYTHON} specification is supported \citep{diffmicro}. In summary the sensor node code generated by both tierless languages, \gls{ITASK} and \gls{MTASK}, is sufficiently memory efficient for the target sensor node hardware. Indeed, the maximum residencies of the \gls{CLEAN} sensor node code is less than the corresponding hand-written (Micro)\gls{PYTHON} code. Of course in a tiered stack the hand-written code can be more easily optimised to minimise residency, and this could even entail using a memory efficienthat thet language like \gls{C}\slash\gls{CPP}. However, such optimisation requires additional developer effort, and a new language would introduce additional semantic friction. \paragraph{Power} Sensor nodes and sensors are designed to have low power demands, and this is particularly important if they are operating on batteries. The grey literature consensus is that with all sensors enabled a sensor node should typically have sub-\qty{1}{\watt} peak power draw. -%\pwtcomment{Mart can you provide some evidence? A citation?}. -%\mlcomment{There only seems to be anecdotal evidence of this. See: \url{https://www.element14.com/community/people/neilk/blog/2019/02/14/investigating-the-power-consumption-of-a-\gls{WEMOS}-d1-mini-esp8266}} -%\pkcomment{We can state that our own measurements are consistent the experience of others.} The \gls{WEMOS} sensor nodes used in \gls{CWS} and \gls{PWS} have the low power consumption of a typical embedded device: with all sensors enabled, they consume around \qty{0.2}{\watt}. The Raspberry Pi supersensor node used in \gls{CRS} and \gls{PRS} use more power as they have a general purpose ARM processor and run mainstream Linux. With all sensors enabled, they consume \qtyrange{1}{2}{\watt}, depending on ambient load. So a microprocessor sensor node consumes an order of magnitude less power than a supersensor node. @@ -904,7 +895,6 @@ Interoperation \emph{increases the cognitive load on the developer} who must sim The developer must \emph{correctly interoperate the components}, e.g.\ adhere to the \gls{API} or communication protocols between components. The interoperation often entails additional programming tasks like marshalling or demarshalling data between components. For example, in the tiered \gls{PRS} and \gls{PWS} architectures, \gls{JSON} is used to serialise and deserialise data strings from the \gls{PYTHON} collector component before storing the data in the Redis database (\cref{lst_t4t:json}). %e.g.\ to marshall and demarshall data between components. -%\mlcomment{A listing must have a caption for it to be labeled and referenced} \begin{lstPython}[caption={\Gls{JSON} Data marshalling in \gls{PRS} and \gls{PWS}: sensor node above, server below.},label={lst_t4t:json}] channel = 'sensor_status.%s.%s' % (hostname, @@ -1083,7 +1073,6 @@ In summary, while a tiered approach makes replacing components easy, refactoring \subsection{Support}% \label{sec_t4t:support} -%\mlcomment{I've shortened this quite a bit} Community and tool support are essential for engineering reliable production software. \Gls{PRS} and \gls{PWS} are both \gls{PYTHON} based, and \gls{PYTHON}\slash\gls{MICROPYTHON} are among the most popular programming languages \citep{cass2020top}. \Gls{PYTHON} is also a common choice for some tiers of \gls{IOT} applications \citep{tanganelli2015coapthon}. Hence, there are a wide range of development tools like \glspl{IDE} and debuggers, a thriving community and a wealth of training material. There are even specialised \gls{IOT} Boards like PyBoard \& WiPy that are specifically programmed using \gls{PYTHON} variations like \gls{MICROPYTHON}. @@ -1141,11 +1130,8 @@ Here we investigate the restrictions imposed by resource-constrained sensor node \Gls{MTASK} programs do not support user defined higher order functions, the only higher order functions available are the predefined \gls{MTASK} combinators. Programmers can, however, use any construct of the \gls{CLEAN} host language to construct an \gls{MTASK} program, including higher order functions and arbitrary data types. For example folding an \gls{MTASK} combinator over a list of tasks. The only restriction is that any higher order function must be macro expanded to a first order \gls{MTASK} program before being compiled to byte code. -%\mlcomment{Pieter: Refine paragraph about macro expansion and currying/HOF} As an example in \cref{lst_t4t:mtasktemp} we use \cleaninline{temperature dht >>~.} \cleaninline{setSds localSds} instead of \cleaninline{temperature dht >>~.} \cleaninline{\\temp -> setSds localSds temp}. %However, this is limited to situations where the expressions are expanded to the required \gls{MTASK} types, i.e.\ the host language acts as a macro language for \gls{MTASK}. -%\mlcomment{I've refined this. The host language does not offer limited use of HOF and currying. It only appears to offer, just macro expansion}. -%\pwtcomment{I've rewritten: please check.} In contrast to \gls{ITASK}, \gls{MTASK} programs have no user defined or recursive data types. It is possible to add user defined types---as long as they are not sum types---to \gls{MTASK}, but this requires significant programming effort. Due to the language being shallowly embedded, pattern matching and field selection on user defined types is not readily available and thus needs to be built into the language by hand. @@ -1202,8 +1188,6 @@ We show that \emph{tierless languages have the potential to significantly improv We illustrate higher order failure management in \gls{CLEAN}\slash\gls{ITASK}/\gls{MTASK} in contrast to the \gls{PYTHON}-based failure management in \gls{PRS}. For maintainability a tiered approach makes replacing components easy, but refactoring within the components is far harder than in a tierless \gls{IOT} language. Again our findings are consistent with the simplied \textit{Code Maintenance} benefits claimed for tierless languages \citep{weisenburger2020survey}. Finally, we contrast community support for the technologies (\cref{sec_t4t:Discussion}). -%\pwtcomment{Pieter: please check discussion of \citep{weisenburger2020survey} in preceding 2 paragraphs} - We report \emph{the first comparison of a tierless \gls{IOT} codebase for resource-rich sensor nodes with one for resource-constrained sensor nodes}. \begin{enumerate*} \item The tierless implementations have very similar code sizes (\gls{SLOC}), as do the tiered implementations: less than 7\% difference in \cref{table_t4t:multi}. This suggests that the development and maintenance effort of simple tierless \gls{IOT} systems for resource-constrained and for resource-rich sensor nodes is similar, as it is for tiered technologies. -- 2.20.1