It's a Jungle Out There Matúš Tomlein PhD Fellow at Aarhus University @matus_tomlein Aarhus.rb meetup, 5.1.2015
Jul 18, 2015
It's a Jungle Out ThereMatúš Tomlein
PhD Fellow at Aarhus University @matus_tomlein
Aarhus.rb meetup, 5.1.2015
The Internet of Things Is
• A buzzword
• Connecting every-day devices to the Internet
• Washing machines, doors, shoes, ...
Charts From Every Talk About IoT
The Old Internet
twitter.com spotify.com
Clients
Servers
POST /tweet GET /songs/next
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
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
What is the development for the IoT like?
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
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)
At least the last point is not true
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
MRuby is Lightweight
• Only platform independent functionality
• Everything else is a gem (mrbgem)
• e.g. IO, threads, require
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
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
4 Ways to Run MRuby
1. Interpreted
2. Interactive shell
3. Bytecode
4. Generating C code
Source: http://blog.mruby.sh/201207020720.html
Interpreted
• Just like any other Ruby app
$ mruby hello_world.rbHello World
• Good for testing
• Overhead
Interactive Shell
• Just like irb
$ mirbmirb - Embeddable Interactive Ruby Shell
> puts "Hello"Hello => nil
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
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
Performance
• Performance of C compared to MRuby is about 100 : 1
• Probably slower than the latest Ruby
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
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)
So, now we have the MRuby, we just need the
MRuby on Rails
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