Overveld Van J IM9906 AF SE Scriptie Pure
Total Page:16
File Type:pdf, Size:1020Kb
MASTER'S THESIS Abstractions for software communication Programming protocols in typescript van Overveld, J. (Jan) Award date: 2020 Link to publication General rights Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain • You may freely distribute the URL identifying the publication in the public portal ? Take down policy If you believe that this document breaches copyright please contact us at: [email protected] providing details and we will investigate your claim. Downloaded from https://research.ou.nl/ on date: 27. Sep. 2021 Open Universiteit www.ou.nl ABSTRACTIONS FOR SOFTWARE COMMUNICATION PROGRAMMING PROTOCOLS IN TYPESCRIPT THESIS Author Jan van Overveld Student number Date of defence 7 February 2020 ABSTRACTIONS FOR SOFTWARE COMMUNICATION PROGRAMMING PROTOCOLS IN TYPESCRIPT by Jan van Overveld in partial fulfillment of the requirements for the degree of Master of Science in Software Engineering at the Open University Student number 851669922 Faculty Faculty of Management, Science and Technology Institute Open University of the Netherlands Course IM9906 Graduation assignment Master program Master’s Programme in Software Engineering Supervisor dr. ir. Sung-Shik Jongmans Open University Chairman Prof. dr. M. C. J. D. van Eekelen Open University ABSTRACT More software parallelization results in more software communication and therefore the need for software communication protocols. Protocol logic in a program is also called the coordination concern. Separating this coordination concern from the regular computation concern in a distributed application can result in higher quality software code. This can be achieved by providing a software engineer facilities for programming protocols based on a global protocol definition. Not only will the coordination be separated from the compu- tation concern, but the defined protocol can also be statically validated. Generating the coordination layer for a distributed application also saves time and reduces programming errors instead of implementing this layer manually. This thesis reports on research for adding software protocol abstractions to the pro- gramming language TypeScript. TypeScript is a statically compiled and typed version of the programming language JavaScript, which is a popular language for programming dis- tributed applications. Various concrete abstractions that are needed for the protocol abstraction layer are di- vided over three conceptual layers. The first conceptual layer provides abstractions needed for starting the protocol and a role based messaging system. The second layer provides a programming interface for each distributed process that is part of the protocol. This in- terface will enable static protocol validation and with a professional development environ- ment, facilities like code statement completion and code navigation will be present. The third layer provides the global protocol definition with the corresponding programming syntax, through an external DSL. A runtime facility for starting up the protocol, to make sure all involved distributed soft- ware processes are present, is called the Mediator. This Mediator role collects the physical address details of all the protocol involved roles and delivers this information to these roles. After this startup process the Mediator dies and the protocol has started for the involved protocol roles. Messages are specified and can be continuously received, but processed when a role is ready for a specific message. Static protocol validation is based on state machine simulation per role. The generated API will have objects for all states, and the methods of these objects represent the transitions between states. These transitions can only be made once, which is checked at runtime to guarantee protocol safety. Performance penalty tests indicate a low decrease of performance due to the extra abstraction layer, and this happens only when the amount of messages increase to high volumes. Normally the implementation of the coordination concern of a distributed application can be error prone, but with a generated coordination layer and static validation, protocol constraints are enforced and therefore errors are reduced. 2 CONTENTS List of Figures 5 1 Introduction6 1.1 Distributed systems....................................6 1.2 Software protocol.....................................7 1.3 Separation of Concerns (SoC)..............................7 1.4 Protocol languages....................................7 1.5 Master research......................................8 1.5.1 RQ1: what abstractions.............................9 1.5.2 RQ2: protocol engine...............................9 1.5.3 RQ3: message passing..............................9 1.5.4 RQ4: GPL or DSL.................................9 1.5.5 RQ5: performance penalty........................... 10 1.6 Contribution........................................ 10 2 Preliminaries 11 2.1 Protocol abstractions................................... 11 2.1.1 Behavioral abstractions............................. 12 2.1.2 Oracle Workflow.................................. 12 2.1.3 Scribble....................................... 13 2.1.4 Jolie......................................... 15 2.1.5 Architecture of software protocols....................... 18 2.2 TypeScript......................................... 19 2.2.1 Introduction.................................... 19 2.2.2 JavaScript...................................... 20 2.2.3 TypeScript, JavaScript that scales....................... 23 2.2.4 Node.js, one language to rule them all.................... 24 3 Results 26 3.1 Alice and Bob........................................ 27 3.2 Layer one, role based communication......................... 32 3.2.1 Mediator...................................... 33 3.2.2 Messages store................................... 35 3.2.3 Alice and Bob implemented with layer one facilities............ 36 3.3 Layer two, static protocol validation.......................... 39 3.3.1 Local perspective state machines....................... 39 3.3.2 JSON with local perspectives.......................... 41 3.3.3 Role implementation in TypeScript...................... 42 3.3.4 Additional comments.............................. 46 3 4 CONTENTS 3.4 Layer three, global protocol definition......................... 46 3.5 Conclusion......................................... 47 3.5.1 API generating process.............................. 48 3.5.2 Complexity..................................... 48 4 Conclusion 52 4.1 RQ1:What abstractions.................................. 52 4.2 RQ2:Protocol engine................................... 53 4.3 RQ3:Message passing................................... 54 4.4 RQ4:GPL or DSL...................................... 55 4.5 RQ5:Performance penalty................................ 55 4.6 Validation and conclusion................................ 59 4.7 Project scope........................................ 60 4.8 Evaluation, discussion and future work........................ 60 Glossary 61 Bibliography 62 Academic............................................. 62 Non-academic.......................................... 64 A Appendix code examples 65 A.1 Message server....................................... 65 A.2 Message client....................................... 66 A.3 Global objects....................................... 66 A.4 Message store....................................... 69 A.5 Message definitions.................................... 70 A.6 Generated API for Alice.................................. 71 A.7 Generated API for Bob.................................. 73 A.8 Perfect number global protocol definition...................... 75 LISTOF FIGURES 2.1 Scribble framework overview............................. 14 2.2 Alice and Bob global protocol............................. 14 2.3 Local perspective of Alice............................... 16 2.4 Local perspective of Bob................................ 16 2.5 TypeScript a superset of JavaScript.......................... 19 2.6 The JavaScript eventloop............................... 21 2.7 TypeScript a superset of ECMAScript........................ 23 3.1 Layered abstraction architecture for distributed software communication.. 27 3.2 Alice and Bob global protocol............................. 28 3.3 Mediator role responsible for protocol startup................... 33 3.4 Local perspective of Alice and Bob.......................... 40 3.5 Protocol statically checked and statement completion.............. 44 3.6 Protocol data type inference.............................. 45 3.7 Local perspective of Fred............................... 48 3.8 State diagram for Bob when dealing with an extra role.............. 49 3.9 Sequence diagram of Alice, Bob and Fred example................ 51 4.1 Performance graph with amount of numbers divided in groups of 100..... 57 4.2 Performance graph with amount of numbers divided in groups of 1000.... 58 4.3 Performance graph with amount of numbers divided in groups of 10000... 58 5 1 INTRODUCTION It is very likely that software processes will become increasingly concurrent