SlideShare a Scribd company logo
1 of 66
Download to read offline
Daniel Bovensiepen
Shrink To Grow
mruby
m for ...
m for ...
minimal
Binary Size
< 100kB
Memory Footprint
< 40kB RAM
m for ...
m for ...
embedded
https://github.com/matsumoto-r/mod_mruby
mod_mruby
LoadModule mruby_module modules/mod_mruby.so
AddHandler mruby-script .rb
backends = [
"http://192.168.0.101:8888/",
"http://192.168.0.102:8888/",
"http://192.168.0.103:8888/",
"http://192.168.0.104:8888/",
]
# write balancing algorithm here.
r = Apache::Request.new()
r.handler = "proxy-server"
r.proxyreq = Apache::PROXYREQ_REVERSE
r.filename = "proxy:" +
backends[rand(backends.length)] +
r.uri
Apache::return(Apache::OK)
https://github.com/matsumoto-r/mod_mruby
mod_mruby
https://github.com/spiritloose/sqlite3ext-mruby
sqlite3ext-mruby
$ cat test.rb
def fib(n)
n < 2 ? n : fib(n - 1) + fib(n - 2)
end
create_function :fib do |n|
fib(n)
end
$ LD_LIBRARY_PATH=. sqlite3
sqlite> .load libsqlite3ext_mruby.so.1.0.0;
sqlite> SELECT mrb_load('test.rb');
sqlite> SELECT fib(30);
832040
sqlite>
https://github.com/spiritloose/sqlite3ext-mruby
sqlite3ext-mruby
Embed
ArangoDB , Redis,
mobiruby, Android, SMC
ArangoDB: http://www.arangodb.org
Redis: https://github.com/antirez/redis/pull/848
mobiruby (iOS): http://mobiruby.org
Android: http://podtynnyi.com/2012/11/29/build-mruby-for-android/
SMC: http://www.secretmaryo.org, https://github.com/Quintus/SMC
m for ...
m for ...
modular
Add/Remove Features
(i.e. Fiber, stdio, ObjectSpace, etc.)
Standard Library
$ ./bin/mirb
mirb - Embeddable Interactive Ruby Shell
This is a very early version, please test and report
errors.
Thanks :)
> Thread
NameError: uninitialized constant Thread
> Fiber
NameError: uninitialized constant Fiber
> eval "puts 'hello world'"
NotImplementedError: eval not implemented
> print "Test"
NotImplementedError: print not available
> ObjectSpace
NameError: uninitialized constant ObjectSpace
> require 'file'
NoMethodError: undefined method 'require' for main
Add/Remove Features
(i.e. Fiber, stdio, ObjectSpace, etc.)
Standard Library
RegExp
Oniguruma & Henry Spencer Engine
Overview: http://blog.mruby.sh/201302190729.html
Oniguruma: http://www.geocities.jp/kosako3/oniguruma/
Henry Spencer Engine: http://www.arglist.com/regex
How
is this possible?
Implementation
rewritten in C99
Implementation
ISO 30170:2012
EXECUTING
RUBY CODE
Five Ways to execute mruby: http://blog.mruby.sh/201207020720.html
mrbc, mruby and mirb
Build System
Makefile, cmake and ...
Rake
Build System
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# include the default GEMs
conf.gembox 'default'
end
# Define cross build settings
MRuby::CrossBuild.new('32bit') do |conf|
toolchain :gcc
conf.cc.flags << "-m32"
conf.linker.flags << "-m32"
end
Rake
Build System
mrbgems
mrbgems
mgem is like RubyGem but incompatible
mrbgems
mrbgems
mruby.c CC mruby
mrbgems
mruby.c CC mrubymgem activate
+mgem +Fiber(i.e. Fiber)
What
can we do now?
mruby on Arduino
C++ Code
Arduino
C++ Code
Arduino
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Workflow
Arduino
Workflow
Arduino
code.cpp
Workflow
Arduino
code.cpp a.binCross-CC
Workflow
Arduino
code.cpp a.binCross-CC .Upload
Cross-Compile
Atmel SAM3X8E (ARM Cortex-M3 based)
Cross-Compile
Atmel SAM3X8E (ARM Cortex-M3 based)
Cross-Compile
MRuby::CrossBuild.new("Arduino Due") do |conf|
toolchain :gcc
ARDUINO_PATH = '/home/daniel/Downloads/arduino-1.5.2'
BIN_PATH = "#{ARDUINO_PATH}/hardware/tools/g++_arm_none_eabi/bin"
SAM_PATH = "#{ARDUINO_PATH}/hardware/arduino/sam"
TARGET_PATH = "#{SAM_PATH}/variants/arduino_due_x"
conf.cc do |cc|
cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"
cc.include_paths = ["#{SAM_PATH}/system/libsam -I#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
"#{SAM_PATH}/system/CMSIS/Device/ATMEL/",
"#{SAM_PATH}/cores/arduino -I#{TARGET_PATH}",
"#{MRUBY_ROOT}/include"]
cc.flags << '-Os -w -ffunction-sections -fdata-sections -nostdlib ' +
'--param max-inline-insns-single=500 -Dprintf=iprintf ' +
'-mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 ' +
'-D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON'
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
end
conf.archiver do |archiver|
archiver.command = "#{BIN_PATH}/arm-none-eabi-ar"
archiver.archive_options = 'rcs %{outfile} %{objs}'
end
conf.bins = []
end
Arduino Ecosystem
Embed
Arduino Ecosystem
Embed
#include "Arduino.h"
#include "../mruby_src/include/mruby.h"
mrb_state *mrb;
/* Init phase of Microcontroller */
void
setup() { }
/* Process Loop */
void
loop() {
mrb = mrb_open();
/* Use mruby here */
mrb_close(mrb);
}
Arduino Ecosystem (API)
Embed
Arduino Ecosystem (API)
Embed
/* ... */
mrb_value
mrb_ar(mrb_state *mrb, mrb_value self) {
mrb_int pin;
mrb_get_args(mrb, "i", &pin);
return mrb_fixnum_value(analogRead(pin));
}
/* ... */
/* Integrate into mruby */
RClass *am = mrb_define_module(mrb, "Arduino");
mrb_define_module_function(mrb, am, "analog_read", mrb_ar, ARGS_REQ(1));
/* ... */
Shrink
available 96kB SRAM and 512kB Flash
Shrink
available 96kB SRAM and 512kB Flash
Shrink
0
16000
32000
48000
64000
80000
96000
112000
128000
144000
160000
nothing mrb_open wrd box nan box flt seglist heap khash mrblib ALL (-flt -wrd) ALL (-nan)
Image (bytes) Free Memory (bytes) Execution Time (µs)
Shrink
96kB SRAM available (~31kB used)
512kb Flash available (~86kB used)
Workflow (mruby)
Arduino
Workflow (mruby)
Arduino
mruby.c
Workflow (mruby)
Arduino
mruby.c
mruby¹
(host)cc
Workflow (mruby)
Arduino
mruby.c
mruby¹
(host)cc
mruby²
(target)
cross-cc
Workflow (mruby)
Arduino
code.rb
mruby.c
mruby¹
(host)cc
mruby²
(target)
cross-cc
Workflow (mruby)
Arduino
code.rb
array.c
(Array)
mruby.c
mruby¹
(host)cc
mruby²
(target)
cross-cc
mrbc¹
Workflow (mruby)
Arduino
code.rb
array.c
(Array)
code.cpp
mruby.c
mruby¹
(host)cc
mruby²
(target)
cross-cc
mrbc¹ integrate
Workflow (mruby)
Arduino
code.rb
array.c
(Array)
code.cpp
mruby.c
mruby¹
(host)cc
mruby²
(target)
code.cpp
+
mruby²
cross-cc
mrbc¹ integrate
Workflow (mruby)
Arduino
code.rb
array.c
(Array)
code.cpp
mruby.c
mruby¹
(host)cc
mruby²
(target)
code.cpp
+
mruby²
a.bin
cross-cc
mrbc¹ integrate
cross-cc
Workflow (mruby)
Arduino
code.rb
array.c
(Array)
code.cpp
mruby.c
mruby¹
(host)cc
mruby²
(target)
code.cpp
+
mruby²
a.bin .
cross-cc
mrbc¹ integrate
cross-cc upload
Workflow (mruby)
Arduino
code.rb
array.c
(Array)
code.cpp
mruby.c
mruby¹
(host)cc
mruby²
(target)
code.cpp
+
mruby²
a.bin .
cross-cc
mrbc¹ integrate
cross-cc upload
OMG
Port mirb to Arduino Due
Arduino
Port mirb to Arduino Due
Arduino
.enter .rb
Interactive Arduino Shell (LED Switch)
Arduino
Interactive Arduino Shell (3D Printer)
Arduino
Coming Next
“Webruby”
by
Xuejie Xiao
THX
@bovensiepen
http://mruby.sh

More Related Content

What's hot

Algorithm cup 2010
Algorithm cup 2010Algorithm cup 2010
Algorithm cup 2010
Wizche
 
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
Ryosuke IWANAGA
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
Cloudflare
 

What's hot (20)

Gameboy emulator in rust and web assembly
Gameboy emulator in rust and web assemblyGameboy emulator in rust and web assembly
Gameboy emulator in rust and web assembly
 
Redis as a message queue
Redis as a message queueRedis as a message queue
Redis as a message queue
 
agri inventory - nouka data collector / yaoya data convertor
agri inventory - nouka data collector / yaoya data convertoragri inventory - nouka data collector / yaoya data convertor
agri inventory - nouka data collector / yaoya data convertor
 
Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話Go初心者がGoでコマンドラインツールの作成に挑戦した話
Go初心者がGoでコマンドラインツールの作成に挑戦した話
 
A little systemtap
A little systemtapA little systemtap
A little systemtap
 
Go memory
Go memoryGo memory
Go memory
 
Algorithm cup 2010
Algorithm cup 2010Algorithm cup 2010
Algorithm cup 2010
 
Puppet User Group Presentation - 15 March 2012
Puppet User Group Presentation - 15 March 2012Puppet User Group Presentation - 15 March 2012
Puppet User Group Presentation - 15 March 2012
 
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
[214] Ai Serving Platform: 하루 수 억 건의 인퍼런스를 처리하기 위한 고군분투기
 
Docker導入手順
Docker導入手順Docker導入手順
Docker導入手順
 
Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)Building a DSL with GraalVM (VoxxedDays Luxembourg)
Building a DSL with GraalVM (VoxxedDays Luxembourg)
 
Jk rubyslava 25
Jk rubyslava 25Jk rubyslava 25
Jk rubyslava 25
 
Go Memory
Go MemoryGo Memory
Go Memory
 
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
"Ops Tools with Perl" 2012/05/12 Hokkaido.pm
 
Docker tips-for-java-developers
Docker tips-for-java-developersDocker tips-for-java-developers
Docker tips-for-java-developers
 
Nginx-lua
Nginx-luaNginx-lua
Nginx-lua
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
 
Go debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFxGo debugging and troubleshooting tips - from real life lessons at SignalFx
Go debugging and troubleshooting tips - from real life lessons at SignalFx
 
Make A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst FrameworkMake A Shoot ‘Em Up Game with Amethyst Framework
Make A Shoot ‘Em Up Game with Amethyst Framework
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 

Similar to Shrink to grow

Similar to Shrink to grow (20)

Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
 
Basicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt applicationBasicsof c make and git for a hello qt application
Basicsof c make and git for a hello qt application
 
Postgres the hardway
Postgres the hardwayPostgres the hardway
Postgres the hardway
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Bare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and ChefBare Metal to OpenStack with Razor and Chef
Bare Metal to OpenStack with Razor and Chef
 
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them AllScylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
Scylla Summit 2022: ScyllaDB Rust Driver: One Driver to Rule Them All
 
Using GPUs to handle Big Data with Java by Adam Roberts.
Using GPUs to handle Big Data with Java by Adam Roberts.Using GPUs to handle Big Data with Java by Adam Roberts.
Using GPUs to handle Big Data with Java by Adam Roberts.
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
Building a DSL with GraalVM (CodeOne)
Building a DSL with GraalVM (CodeOne)Building a DSL with GraalVM (CodeOne)
Building a DSL with GraalVM (CodeOne)
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destruction
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destructionDEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destruction
DEF CON 27 - PATRICK WARDLE - harnessing weapons of Mac destruction
 
One-Man Ops
One-Man OpsOne-Man Ops
One-Man Ops
 
Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloud
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Intro django
Intro djangoIntro django
Intro django
 
How to create your own hack environment
How to create your own hack environmentHow to create your own hack environment
How to create your own hack environment
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Shrink to grow