24
It's a Jungle Out There Matúš Tomlein PhD Fellow at Aarhus University @matus_tomlein Aarhus.rb meetup, 5.1.2015

It's a Jungle Out There – IoT and MRuby

Embed Size (px)

Citation preview

Page 1: It's a Jungle Out There – IoT and MRuby

It's a Jungle Out ThereMatúš Tomlein

PhD Fellow at Aarhus University @matus_tomlein

Aarhus.rb meetup, 5.1.2015

Page 2: It's a Jungle Out There – IoT and MRuby

The Internet of Things Is

• A buzzword

• Connecting every-day devices to the Internet

• Washing machines, doors, shoes, ...

Page 3: It's a Jungle Out There – IoT and MRuby

Charts From Every Talk About IoT

Page 4: It's a Jungle Out There – IoT and MRuby

The Old Internet

twitter.com spotify.com

Clients

Servers

POST /tweet GET /songs/next

Page 5: It's a Jungle Out There – IoT and MRuby

The New Internet

twitter.com

Clients

Servers

POST /tweet

FE80::0202:B3FF:FE1E:8329

GET /fuel POST /activate

AB78::1378:F3BB:FE1E:8329

GET /status

Page 6: It's a Jungle Out There – IoT and MRuby

Well, actually...

twitter.com

Clients

Servers

POST /tweet

FE80::0202:B3FF:FE1E:8329

GET /fuel POST /lamps/12/activate

AB78::1378:F3BB:FE1E:8329

GET /status

Page 7: It's a Jungle Out There – IoT and MRuby

What is the development for the IoT like?

Page 8: It's a Jungle Out There – IoT and MRuby

We, Web developers, Are Spoiled• Deploying/updating our apps is easy

• Only have to care about a few of servers in the production

• We can always SSH into a server and see what's wrong

• Our servers run in the comfort of the cloud

• Testing/debugging also easy

• We have all the computing power we want

• We can use any technology we want

Page 9: It's a Jungle Out There – IoT and MRuby

Meanwhile on Embedded Devices

• Deploying/updating is a nightmare

• There can be dozens/thousands of embedded systems running your app

• Little power, sometimes constrained battery life

• Testing/debugging on the device takes effort

• You have no control of the environment they are in

• The added trouble of communication with and between devices

• Security...

• You are stuck with C, C++, maybe Java (unless you run on Unix)

Page 10: It's a Jungle Out There – IoT and MRuby

At least the last point is not true

Page 11: It's a Jungle Out There – IoT and MRuby

MRuby• Another interpreter for Ruby

• The other ones won't run without OS or on RTOS

• Also a compiler and VM

• Very lightweight (<128kb)

• Compatible with Ruby 1.9 syntax

• Runs on anything that can run C

Page 12: It's a Jungle Out There – IoT and MRuby

MRuby is Lightweight

• Only platform independent functionality

• Everything else is a gem (mrbgem)

• e.g. IO, threads, require

Page 13: It's a Jungle Out There – IoT and MRuby

mrbgems• Defined in build_config.rb

• Can be:

• Pure Ruby – Defines the extension class in Ruby

• Pure C – Builds the class in C

• C and Ruby – Defines some methods in C and some in Ruby

Page 14: It's a Jungle Out There – IoT and MRuby

MRuby is Embeddable

• Can be run inside other applications

• Great for scripting, configuration

*.rb

/usr/bin/ruby C/C++ app

*.rb bytecode

libmruby.a

Source: http://www.slideshare.net/yamanekko/rubyconf2013?qid=dd845db4-dda5-44a5-81c3-0fa63ca520f2&v=qf1&b=&from_search=8

Page 15: It's a Jungle Out There – IoT and MRuby

4 Ways to Run MRuby

1. Interpreted

2. Interactive shell

3. Bytecode

4. Generating C code

Source: http://blog.mruby.sh/201207020720.html

Page 16: It's a Jungle Out There – IoT and MRuby

Interpreted

• Just like any other Ruby app

$ mruby hello_world.rbHello World

• Good for testing

• Overhead

Page 17: It's a Jungle Out There – IoT and MRuby

Interactive Shell

• Just like irb

$ mirbmirb - Embeddable Interactive Ruby Shell

> puts "Hello"Hello => nil

Page 18: It's a Jungle Out There – IoT and MRuby

Bytecode$ mrbc hello_world.rb

• Will produce platform independent bytecode in hello_world.mrb

$ mruby -b hello_world.mrbHello World

• Will run the bytecode in a VM

• Less overhead – no parsing

• Still need the mruby program to run it

Page 19: It's a Jungle Out There – IoT and MRuby

Generating C Code

• Integrate Ruby code in a C application

• Generates C files containing the Ruby code

• A standalone app – without any requirements

• The user doesn't see the source code

Page 20: It's a Jungle Out There – IoT and MRuby

Performance

• Performance of C compared to MRuby is about 100 : 1

• Probably slower than the latest Ruby

Page 21: It's a Jungle Out There – IoT and MRuby

But That's OK• There is a trend in IoT:

• Dumb devices that only provide resources/services

• Most of the application logic in the cloud

• MRuby fits this use case well despite performance issues

• Besides it's very young and will improve

Page 22: It's a Jungle Out There – IoT and MRuby

One Less Issue• Deploying/updating is a nightmare

• There can be dozens/thousands of embedded systems running your app

• Little power, sometimes constrained battery life

• Testing/debugging on the device takes effort

• You have no control of the environment they are in

• The added trouble of communication with and between devices

• Security...

• You are stuck with C, C++, maybe Java (unless you run on Unix)

Page 23: It's a Jungle Out There – IoT and MRuby

So, now we have the MRuby, we just need the

MRuby on Rails

Page 24: It's a Jungle Out There – IoT and MRuby

My PhD Project• A platform/framework for deploying apps to embedded devices

• Define some conventions and architecture

• App Store like software ecosystem

• Secure environment for apps

• Open interfaces and communication

• I'm just starting my PhD

• Any feedback is very appreciated