introduction to iot · introduction to iot.js tilmann scheller principal compiler engineer...
TRANSCRIPT
1Samsung Open Source Group
Introduction to IoT.js
Tilmann SchellerPrincipal Compiler Engineer
Samsung Open Source GroupSamsung Research UK
OpenIoT Summit 2016San Diego, USA, April 4 – 6, 2016
2Samsung Open Source Group
Overview
● Introduction
● JerryScript
● IoT.js
● Memory consumption/Performance
● Demo
● Future work
● Summary
3Samsung Open Source Group
Introduction
4Samsung Open Source Group
What is IoT.js?
● A lightweight version of Node.js
● Attempt to bring the success of Node.js to the embedded world
● Retains backwards compatibility with Node.js as much as possible
● Runs on top of JerryScript
5Samsung Open Source Group
IoT Hardware
http://postscapes.com/internet-of-things-hardware
6Samsung Open Source Group
What is JerryScript?
● A really lightweight JavaScript engine
● Has a base footprint of 10KB of RAM
● Optimized for microcontrollers
● Developed from scratch by Samsung
7Samsung Open Source Group
Why JavaScript on microcontrollers?
● There's a huge pool of JavaScript developers
● Opens up the possibility for web developers to easily write software for embedded devices
● Performance overhead of JavaScript less of an issue for control tasks
● Increased productivity, shorter time to market
● Ability to load code dynamically over the network
● Security: Executing JavaScript code is safer than executing arbitrary native code
8Samsung Open Source Group
Open source
● Actively developed on GitHub
● JerryScript and IoT.js are both open source released under the Apache 2.0 license
● Building up a community around IoT.js/JerryScript
9Samsung Open Source Group
JerryScript
10Samsung Open Source Group
JerryScript History
● Development started in June 2014
● Released as open source in June 2015
● JerryScript passed 100% of the test262 conformance test suite in August 2015
● Rewritten compact byte code implementation landed in January 2016
● Current focus on performance optimization
11Samsung Open Source Group
JerryScript
● Heavily optimized for a low memory footprint
● Interpreter-only
● Compact object representation
● Compressed pointers
● No AST, directly creating byte code
● Compact byte code heavily optimized for low memory consumption
12Samsung Open Source Group
JerryScript Portability
● Extremely portable
● Self-contained
● Small C library
● Can run bare-metal
● Supports the STM32F4, ESP8266 boards
● Runs on Linux/OS X as well
13Samsung Open Source Group
JerryScript
● Written in C99
● About 74KLOC
● Code size ~190KB when compiled with GCC LTO for ARM Thumb-2
● Implements the entire ECMAScript 5.1 standard, passes 100% of the test262 conformance test suite
● C API for embedding JerryScript
● Byte code snapshot feature
14Samsung Open Source Group
JerryScript C API
15Samsung Open Source Group
JerryScript C API
16Samsung Open Source Group
IoT.js
17Samsung Open Source Group
IoT.js
● Lightweight version of Node.js
● Focus on resource-constrained devices
● Tries to retain backwards compatibility
● Mostly written in JavaScript
18Samsung Open Source Group
IoT.js Architecture
19Samsung Open Source Group
IoT.js Modules
● Assert
● Buffer
● DNS
● Events
● File System
● HTTP
● Net
● Modules
● Process
● Stream
● Timers
● GPIO
20Samsung Open Source Group
Target hardware
● STM32F4 developer board
● Cortex-M4F clocked at 168 MHz
● 192KB of RAM
● 1MB of flash memory
21Samsung Open Source Group
NuttX
● Real-time operating system
● Open source (BSD license)
● Scales from 8-bit microcontrollers to 32-bit microcontrollers
● Supports the STM32F4 developer board
22Samsung Open Source Group
libtuv
● libuv - Support library for asynchronous I/O
● libtuv - Stripped down version of Libuv
● Runs on NuttX and Linux
● Experimental support for mbed OS
23Samsung Open Source Group
Memory consumption/Performance
24Samsung Open Source Group
IoT.js - Memory consumption
Measured on a Raspberry Pi 2
Test name IoT.js Node.js
require('http') 40KB 6.70MB
test_httpserver.js 80KB 8.63MB
25Samsung Open Source Group
SunSpider 1.0.2 - Memory consumption
3d-cube
access-binary-trees
access-fannkuch
access-nbody
bitops-3bit-bits-in-byte
bitops-bits-in-byte
bitops-bitwise-and
bitops-nsieve-bits
controlflow-recursive
crypto-aes
crypto-md5
crypto-sha1
date-format-tofte
date-format-xparb
math-cordic
math-partial-sums
math-spectral-norm
string-base64
string-fasta
0 100 200 300 400 500 600 700
76
76
32
36
24
24
24
148
136
104
152
112
60
52
32
28
32
152
44
216
240
160
172
160
160
160
384
204
268
420
304
572
220
164
160
164
324
172
JerryScript
Duktape 1.4
Max RSS in KB (lower is better) Measured on a Raspberry Pi 2
26Samsung Open Source Group
SunSpider 1.0.2 - Performance
3d-cube
access-binary-trees
access-fannkuch
access-nbody
bitops-3bit-bits-in-byte
bitops-bits-in-byte
bitops-bitwise-and
bitops-nsieve-bits
controlflow-recursive
crypto-aes
crypto-md5
crypto-sha1
date-format-tofte
date-format-xparb
math-cordic
math-partial-sums
math-spectral-norm
string-base64
string-fasta
0 2 4 6 8 10 12 14 16 18 20
2.54
1.36
7.38
2.81
1.62
2.39
3.27
17.88
0.95
3.36
3.29
2.07
2.09
0.83
2.83
1.57
1.46
5.08
3.21
1.44
1.78
3.4
2.23
2.42
2.73
10.75
4.52
1.51
2.58
2.08
1.93
4.64
2.23
3.62
3.73
1.13
5.95
6.46
JerryScript
Duktape 1.4
Execution time in seconds (lower is better) Measured on a Raspberry Pi 2
27Samsung Open Source Group
ubench - Memory consumption
loop-sum
loop-empty-resolve
loop-empty
function-sum
function-missing-args
function-excess-args
function-emtpy
function-correct-args
function-closure
0 100 200 300 400 500 600
24
24
24
24
24
24
24
24
32
152
152
152
156
156
156
156
156
496
JerryScript
Duktape 1.4
Max RSS in KB (lower is better) Measured on a Raspberry Pi 2
28Samsung Open Source Group
ubench - Performance
loop-sum
loop-empty-resolve
loop-empty
function-sum
function-missing-args
function-excess-args
function-emtpy
function-correct-args
function-closure
0 10 20 30 40 50 60 70 80 90
35.48
3.42
30.14
18.05
16.09
20.85
19.66
22.18
2.62
76.65
6.41
55.23
23.93
27.35
27.93
38.89
27.95
18.87
JerryScript
Duktape 1.4
Execution time in seconds (lower is better) Measured on a Raspberry Pi 2
29Samsung Open Source Group
Demo
30Samsung Open Source Group
Tetris Demo
● Implementation of the classic Tetris game
● Each device drives one LED matrix as display
● Implemented as a Node.js module
● Both devices are running exactly the same JavaScript code
31Samsung Open Source Group
Demo
Raspberry Pi 2(1GB RAM, 8GB Flash)
TetrisNode.js
V8Linux
STM32F4 board(192KB RAM, 1MB Flash)
TetrisIoT.js
JerryScriptNuttX
USB Keypad
LED Matrix LED Matrix
I2C I2C
Switches via GPIO
32Samsung Open Source Group
Tetris Demo
https://youtu.be/q4iBeOAC7XI
33Samsung Open Source Group
Pong Demo
● Implementation of the classic Pong game
● Display shared across two devices
● Each device drives one LED matrix
● Implemented as a Node.js module
● "AI" oppenent running on the microcontroller
34Samsung Open Source Group
Demo
Raspberry Pi 2(1GB RAM, 8GB Flash)
Pong ClientNode.js
V8Linux
STM32F4 board(192KB RAM, 1MB Flash)
Pong ServerIoT.js
JerryScriptNuttX
Ethernet
USB Keypad
LED Matrix LED Matrix
I2C I2C
35Samsung Open Source Group
Pong Demo
36Samsung Open Source Group
Future work
37Samsung Open Source Group
Future work
● Close performance gap between JerryScript and Duktape
● Further performance and memory optimizations
● Enhance JerryScript C API
● Add more IoT.js modules
● Package manager for IoT.js
● Support more devices
38Samsung Open Source Group
Summary
39Samsung Open Source Group
Summary
● Significantly lowers barrier of entry for JavaScript development targeting heavily constrained embedded devices
● Speeds up development
● Active community
● More information on http://www.jerryscript.net and http://www.iotjs.net
● Looking for bug reports and feedback
Thank you.
40Samsung Open Source Group
41Samsung Open Source Group
Contact Information:
Tilmann [email protected]
Samsung Open Source GroupSamsung Research UK