SlideShare una empresa de Scribd logo
1 de 19
Descargar para leer sin conexión
Running MRuby
                             in a database
                Totally awesome, useful or just another pointless approach?


                                    Frank Celler, triAGENS, Cologne
                                           RuPy 2012, Brno
                                               2012-11-16




                             www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Agenda


                            NoSQL database ArangoDB

                            Use-Cases for actions

                            mruby

                            V8 or mruby?



                                    www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
NoSQL Databases


                     Key/Value Store                                 Document (Object) DB


                                             Graph Database




                                  www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
NoSQL Databases
                                                2012-11-11: 150 DB on
                                                 nosql-databases.org




                     Key/Value Store                                    Document (Object) DB


                                             Graph Database




                                  www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
NoSQL Databases
                                                    2012-11-11: 150 DB on
                                                     nosql-databases.org




                     Key/Value Store                                        Document (Object) DB


                                                 Graph Database

                        Multi-Model
                         Databases                                                     Polyglot
                                                                                      Persistence




                                      www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Multi-Model Open-Source Database

                      Various Indexes: Skip-Lists, Hashes, Geo, Cap

                      Language API/Drivers for big Ps, Ruby, JS

                      Embedded JavaScript & Ruby engine

                      Written in C/C++

                      Query Language for Joins and Sub-Structures

                               www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Query Language:
      FOR u in Users                                        FOR u IN users
       LET rs = (                                            LET friends = (
           FOR r in Recommendations                            FOR p in PATHS(user, relations, ``outbound´´, 1)
             FILTER r.rec_by == u._id && r.type == "Book"      FILTER p._from == u._id
             RETURN r.book_title )                           )
       FILTER                                               RETURN
         length(rs) >= 3                                     { user: u, closeFriends: friends }
       RETURN
         { "name" : u.name, "titles" : rs }

      (compare with UNQL / JSONiq)




                                  www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Use-Cases for
                            script languages
     GET /user/fceller

     function (req, res) {
       var user = db.users.byExample({ username: req.urlParameters.username });
       ... deal with unknown user...
                                                                          enrich
                                                                          result
         user.age = ... compute user age from birthday ...;
         delete user.hashedPassword;

         actions.resultOk(req, res, actions.HTTP_OK, user);       hide info
     }




                              www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Use-Cases for
                            script languages
     GET /user/fceller/eccentricity

     function (req, res) {
       var user = db.users.byExample({ username: req.urlParameters.username });
       ... deal with unknown user...
                                                                        needs
                                                                      every node
         var eccentricity = ... compute eccentricity ...;

         actions.resultOk(req, res, actions.HTTP_OK, eccentricity);
     }




                               www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Use-Cases for
                            script languages

                      Transactions

                      Triggers

                      Predefined Objects for AJAX




                                 www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
MRuby

                                     Matz's
                                  embeddable
                            minimal implementation of
                                 Ruby language



                              www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
MRuby

                            RiteVM as core

                            Minimal standard libraries
                                                                              quotes from Matz
                            Embeddable C API

                            No perfect languages, even Ruby

                            Like to provide choices


                                  www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
MRuby vs V8

                            JavaScript is a “complicated” language for
                            embedding C++ class hierarchies

                            V8 itself is complex (isolates, contexts,
                            handle scopes), but fast

                            mruby is plain and simple C code

                            documentation is sketchy for both


                                   www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
MRuby vs V8

                            def fact n; (n > 1) ? n*fact(n-1) : 1; end

                              mruby: 20 time-units

                              V8: 0.6 time-units

                              php: 20 time-units

                              Ruby 1.9 (int): 9 time-units


                                   www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Why use MRuby?

                            “Like to provide choices”

                              i.e. if you don‘t like prototype inheritance

                            “still young”

                              i.e. instead of using RiteVM, compile to
                              machine code


                                   www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
MRuby and LLVM
                            def fact n; (n > 1) ? n*fact(n-1) : 1; end

                                    000   OP_ENTER    1:0:0:0:0:0:0
                                    001   OP_MOVE     R4      R1
                                    002   OP_LOADI    R5      1
                                    003   OP_LOADNIL  R6
                                    004   OP_GT       R4      '>'       1
                                    005   OP_JMPNOT   R4      017
                                    006   OP_MOVE     R4      R1
                                    007   OP_LOADSELF R5
                                    008   OP_MOVE     R6      R1
                                    009   OP_LOADI    R7      1
                                    010   OP_LOADNIL  R8
                                    011   OP_SUB      R6      '-'       1
                                    012   OP_LOADNIL  R7
                                    013   OP_SEND     R5      'fact'    1
                                    014   OP_LOADNIL  R6
                                    015   OP_MUL      R4      '*'       1
                                    016   OP_JMP              018
                                    017   OP_LOADI    R4      1
                                    018   OP_RETURN   R4


                                www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
MRuby and LLVM
                            CASE(OP_SUB) {
                              /* A B C R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1)*/
                              int a = GETARG_A(i);

                             /* need to check if op is overridden */
                             switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
                             case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
                               {
                                 mrb_int x, y, z;

                                 x = mrb_fixnum(regs[a]);
                                 y = mrb_fixnum(regs[a+1]);
                                 z = x - y;
                                 if (((x < 0) ^ (y < 0)) == 0 && (x < 0) != (z < 0)) {
                                   /* integer overflow */
                                   SET_FLT_VALUE(regs[a], (mrb_float)x - (mrb_float)y);
                                   break;
                                 }
                                 SET_INT_VALUE(regs[a], z);
                               }
                               break;


                   Simply replacing OP codes by machine code already gives a factor of 2


                                        www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Why use MRuby?


                            If you have use-cases for scripts in
                            ArangoDB (or any other database), mruby
                            will eventually be an alternative

                            Otherwise, use a language driver (aka
                            Ashikawa for Ruby) and CRuby or JRuby



                               www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12
Thank You!

                 Stay in Touch:

                       Fork me on github

                       Google Group: ArangoDB

                       Twitter: @fceller & @arangodb

                       www.arangodb.org

                               www.arangodb.org (c) f.celler@triagens.de
Mittwoch, 14. November 12

Más contenido relacionado

La actualidad más candente

Small Overview of Skype Database Tools
Small Overview of Skype Database ToolsSmall Overview of Skype Database Tools
Small Overview of Skype Database Tools
elliando dias
 
Big Data Processing using Apache Spark and Clojure
Big Data Processing using Apache Spark and ClojureBig Data Processing using Apache Spark and Clojure
Big Data Processing using Apache Spark and Clojure
Dr. Christian Betz
 

La actualidad más candente (20)

A Graph Database That Scales - ArangoDB 3.7 Release Webinar
A Graph Database That Scales - ArangoDB 3.7 Release WebinarA Graph Database That Scales - ArangoDB 3.7 Release Webinar
A Graph Database That Scales - ArangoDB 3.7 Release Webinar
 
Multi-model databases and node.js
Multi-model databases and node.jsMulti-model databases and node.js
Multi-model databases and node.js
 
A Little SPARQL in your Analytics
A Little SPARQL in your AnalyticsA Little SPARQL in your Analytics
A Little SPARQL in your Analytics
 
Comparison with storing data using NoSQL(CouchDB) and a relational database.
Comparison with storing data using NoSQL(CouchDB) and a relational database.Comparison with storing data using NoSQL(CouchDB) and a relational database.
Comparison with storing data using NoSQL(CouchDB) and a relational database.
 
Visualize your graph database
Visualize your graph databaseVisualize your graph database
Visualize your graph database
 
Small Overview of Skype Database Tools
Small Overview of Skype Database ToolsSmall Overview of Skype Database Tools
Small Overview of Skype Database Tools
 
Solid pods and the future of the spatial web
Solid pods and the future of the spatial webSolid pods and the future of the spatial web
Solid pods and the future of the spatial web
 
An introduction to Nosql
An introduction to NosqlAn introduction to Nosql
An introduction to Nosql
 
OrientDB: Unlock the Value of Document Data Relationships
OrientDB: Unlock the Value of Document Data RelationshipsOrientDB: Unlock the Value of Document Data Relationships
OrientDB: Unlock the Value of Document Data Relationships
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
MongoDB is the MashupDB
MongoDB is the MashupDBMongoDB is the MashupDB
MongoDB is the MashupDB
 
Introduction to RDFa
Introduction to RDFaIntroduction to RDFa
Introduction to RDFa
 
RDFa Tutorial
RDFa TutorialRDFa Tutorial
RDFa Tutorial
 
Catmandu Librecat
Catmandu LibrecatCatmandu Librecat
Catmandu Librecat
 
State of the Semantic Web
State of the Semantic WebState of the Semantic Web
State of the Semantic Web
 
DataFrame: Spark's new abstraction for data science by Reynold Xin of Databricks
DataFrame: Spark's new abstraction for data science by Reynold Xin of DatabricksDataFrame: Spark's new abstraction for data science by Reynold Xin of Databricks
DataFrame: Spark's new abstraction for data science by Reynold Xin of Databricks
 
RDF SHACL, Annotations, and Data Frames
RDF SHACL, Annotations, and Data FramesRDF SHACL, Annotations, and Data Frames
RDF SHACL, Annotations, and Data Frames
 
OrientDB & Node.js Overview - JS.Everywhere() KW
OrientDB & Node.js Overview - JS.Everywhere() KWOrientDB & Node.js Overview - JS.Everywhere() KW
OrientDB & Node.js Overview - JS.Everywhere() KW
 
Visualizing Web Data Query Results
Visualizing Web Data Query ResultsVisualizing Web Data Query Results
Visualizing Web Data Query Results
 
Big Data Processing using Apache Spark and Clojure
Big Data Processing using Apache Spark and ClojureBig Data Processing using Apache Spark and Clojure
Big Data Processing using Apache Spark and Clojure
 

Destacado

CAP and the Architectural Consequences by martin Schönert
CAP and the Architectural Consequences by martin SchönertCAP and the Architectural Consequences by martin Schönert
CAP and the Architectural Consequences by martin Schönert
ArangoDB Database
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databases
ArangoDB Database
 

Destacado (20)

Backbone using Extensible Database APIs over HTTP
Backbone using Extensible Database APIs over HTTPBackbone using Extensible Database APIs over HTTP
Backbone using Extensible Database APIs over HTTP
 
Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)Hotcode 2013: Javascript in a database (Part 2)
Hotcode 2013: Javascript in a database (Part 2)
 
Complex queries in a distributed multi-model database
Complex queries in a distributed multi-model databaseComplex queries in a distributed multi-model database
Complex queries in a distributed multi-model database
 
GraphDatabases and what we can use them for
GraphDatabases and what we can use them forGraphDatabases and what we can use them for
GraphDatabases and what we can use them for
 
Extensible Database APIs and their role in Software Architecture
Extensible Database APIs and their role in Software ArchitectureExtensible Database APIs and their role in Software Architecture
Extensible Database APIs and their role in Software Architecture
 
Domain Driven Design & NoSQL
Domain Driven Design & NoSQLDomain Driven Design & NoSQL
Domain Driven Design & NoSQL
 
ArangoDB – Persistência Poliglota e Banco de Dados Multi-Modelos
ArangoDB – Persistência Poliglota e Banco de Dados Multi-ModelosArangoDB – Persistência Poliglota e Banco de Dados Multi-Modelos
ArangoDB – Persistência Poliglota e Banco de Dados Multi-Modelos
 
Domain Driven Design & NoSQL
Domain Driven Design & NoSQLDomain Driven Design & NoSQL
Domain Driven Design & NoSQL
 
Multi model-databases
Multi model-databasesMulti model-databases
Multi model-databases
 
Jan Steemann: Modelling data in a schema free world (Talk held at Froscon, 2...
Jan Steemann: Modelling data in a schema free world  (Talk held at Froscon, 2...Jan Steemann: Modelling data in a schema free world  (Talk held at Froscon, 2...
Jan Steemann: Modelling data in a schema free world (Talk held at Froscon, 2...
 
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at... Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
Processing large-scale graphs with Google(TM) Pregel by MICHAEL HACKSTEIN at...
 
Overhauling a database engine in 2 months
Overhauling a database engine in 2 monthsOverhauling a database engine in 2 months
Overhauling a database engine in 2 months
 
guacamole: an Object Document Mapper for ArangoDB
guacamole: an Object Document Mapper for ArangoDBguacamole: an Object Document Mapper for ArangoDB
guacamole: an Object Document Mapper for ArangoDB
 
Domain driven design @FrOSCon
Domain driven design @FrOSConDomain driven design @FrOSCon
Domain driven design @FrOSCon
 
Processing large-scale graphs with Google Pregel
Processing large-scale graphs with Google PregelProcessing large-scale graphs with Google Pregel
Processing large-scale graphs with Google Pregel
 
Wir sind aber nicht Twitter
Wir sind aber nicht TwitterWir sind aber nicht Twitter
Wir sind aber nicht Twitter
 
Domain Driven Design and NoSQL TLV
Domain Driven Design and NoSQL TLVDomain Driven Design and NoSQL TLV
Domain Driven Design and NoSQL TLV
 
Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)Introduction to ArangoDB (nosql matters Barcelona 2012)
Introduction to ArangoDB (nosql matters Barcelona 2012)
 
CAP and the Architectural Consequences by martin Schönert
CAP and the Architectural Consequences by martin SchönertCAP and the Architectural Consequences by martin Schönert
CAP and the Architectural Consequences by martin Schönert
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databases
 

Similar a Running MRuby in a Database - ArangoDB - RuPy 2012

Riak intro to..
Riak intro to..Riak intro to..
Riak intro to..
Adron Hall
 
Python for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasPython for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandas
Wes McKinney
 
Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Slides 111017220255-phpapp01
Slides 111017220255-phpapp01
Ken Mwai
 
Scala overview
Scala overviewScala overview
Scala overview
Steve Min
 
High order bits from cassandra & hadoop
High order bits from cassandra & hadoopHigh order bits from cassandra & hadoop
High order bits from cassandra & hadoop
srisatish ambati
 

Similar a Running MRuby in a Database - ArangoDB - RuPy 2012 (20)

StORM preview
StORM previewStORM preview
StORM preview
 
Introduction to dotNetRDF
Introduction to dotNetRDFIntroduction to dotNetRDF
Introduction to dotNetRDF
 
Publishing RDF SKOS with microservices
Publishing RDF SKOS with microservicesPublishing RDF SKOS with microservices
Publishing RDF SKOS with microservices
 
RDF APIs for .NET Framework
RDF APIs for .NET FrameworkRDF APIs for .NET Framework
RDF APIs for .NET Framework
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)
 
No Sql
No SqlNo Sql
No Sql
 
Nosql and newsql
Nosql and newsqlNosql and newsql
Nosql and newsql
 
Why Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) ModelWhy Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) Model
 
Riak intro to..
Riak intro to..Riak intro to..
Riak intro to..
 
Why Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) ModelWhy Spark Is the Next Top (Compute) Model
Why Spark Is the Next Top (Compute) Model
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Transient and persistent RDF views over relational databases in the context o...
Transient and persistent RDF views over relational databases in the context o...Transient and persistent RDF views over relational databases in the context o...
Transient and persistent RDF views over relational databases in the context o...
 
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
A Tale of Three Apache Spark APIs: RDDs, DataFrames, and Datasets with Jules ...
 
Python for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandasPython for Financial Data Analysis with pandas
Python for Financial Data Analysis with pandas
 
Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Slides 111017220255-phpapp01
Slides 111017220255-phpapp01
 
Neo4jrb
Neo4jrbNeo4jrb
Neo4jrb
 
Scala overview
Scala overviewScala overview
Scala overview
 
Haskell vs. F# vs. Scala
Haskell vs. F# vs. ScalaHaskell vs. F# vs. Scala
Haskell vs. F# vs. Scala
 
High order bits from cassandra & hadoop
High order bits from cassandra & hadoopHigh order bits from cassandra & hadoop
High order bits from cassandra & hadoop
 
Graph databases & data integration v2
Graph databases & data integration v2Graph databases & data integration v2
Graph databases & data integration v2
 

Más de ArangoDB Database

Más de ArangoDB Database (20)

ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....
ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....
ATO 2022 - Machine Learning + Graph Databases for Better Recommendations (3)....
 
Machine Learning + Graph Databases for Better Recommendations V2 08/20/2022
Machine Learning + Graph Databases for Better Recommendations V2 08/20/2022Machine Learning + Graph Databases for Better Recommendations V2 08/20/2022
Machine Learning + Graph Databases for Better Recommendations V2 08/20/2022
 
Machine Learning + Graph Databases for Better Recommendations V1 08/06/2022
Machine Learning + Graph Databases for Better Recommendations V1 08/06/2022Machine Learning + Graph Databases for Better Recommendations V1 08/06/2022
Machine Learning + Graph Databases for Better Recommendations V1 08/06/2022
 
ArangoDB 3.9 - Further Powering Graphs at Scale
ArangoDB 3.9 - Further Powering Graphs at ScaleArangoDB 3.9 - Further Powering Graphs at Scale
ArangoDB 3.9 - Further Powering Graphs at Scale
 
GraphSage vs Pinsage #InsideArangoDB
GraphSage vs Pinsage #InsideArangoDBGraphSage vs Pinsage #InsideArangoDB
GraphSage vs Pinsage #InsideArangoDB
 
Webinar: ArangoDB 3.8 Preview - Analytics at Scale
Webinar: ArangoDB 3.8 Preview - Analytics at Scale Webinar: ArangoDB 3.8 Preview - Analytics at Scale
Webinar: ArangoDB 3.8 Preview - Analytics at Scale
 
Graph Analytics with ArangoDB
Graph Analytics with ArangoDBGraph Analytics with ArangoDB
Graph Analytics with ArangoDB
 
Getting Started with ArangoDB Oasis
Getting Started with ArangoDB OasisGetting Started with ArangoDB Oasis
Getting Started with ArangoDB Oasis
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDB
 
Hacktoberfest 2020 - Intro to Knowledge Graphs
Hacktoberfest 2020 - Intro to Knowledge GraphsHacktoberfest 2020 - Intro to Knowledge Graphs
Hacktoberfest 2020 - Intro to Knowledge Graphs
 
gVisor, Kata Containers, Firecracker, Docker: Who is Who in the Container Space?
gVisor, Kata Containers, Firecracker, Docker: Who is Who in the Container Space?gVisor, Kata Containers, Firecracker, Docker: Who is Who in the Container Space?
gVisor, Kata Containers, Firecracker, Docker: Who is Who in the Container Space?
 
ArangoML Pipeline Cloud - Managed Machine Learning Metadata
ArangoML Pipeline Cloud - Managed Machine Learning MetadataArangoML Pipeline Cloud - Managed Machine Learning Metadata
ArangoML Pipeline Cloud - Managed Machine Learning Metadata
 
ArangoDB 3.7 Roadmap: Performance at Scale
ArangoDB 3.7 Roadmap: Performance at ScaleArangoDB 3.7 Roadmap: Performance at Scale
ArangoDB 3.7 Roadmap: Performance at Scale
 
Webinar: What to expect from ArangoDB Oasis
Webinar: What to expect from ArangoDB OasisWebinar: What to expect from ArangoDB Oasis
Webinar: What to expect from ArangoDB Oasis
 
ArangoDB 3.5 Feature Overview Webinar - Sept 12, 2019
ArangoDB 3.5 Feature Overview Webinar - Sept 12, 2019ArangoDB 3.5 Feature Overview Webinar - Sept 12, 2019
ArangoDB 3.5 Feature Overview Webinar - Sept 12, 2019
 
3.5 webinar
3.5 webinar 3.5 webinar
3.5 webinar
 
Webinar: How native multi model works in ArangoDB
Webinar: How native multi model works in ArangoDBWebinar: How native multi model works in ArangoDB
Webinar: How native multi model works in ArangoDB
 
An introduction to multi-model databases
An introduction to multi-model databasesAn introduction to multi-model databases
An introduction to multi-model databases
 
Running complex data queries in a distributed system
Running complex data queries in a distributed systemRunning complex data queries in a distributed system
Running complex data queries in a distributed system
 
Guacamole Fiesta: What do avocados and databases have in common?
Guacamole Fiesta: What do avocados and databases have in common?Guacamole Fiesta: What do avocados and databases have in common?
Guacamole Fiesta: What do avocados and databases have in common?
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Running MRuby in a Database - ArangoDB - RuPy 2012

  • 1. Running MRuby in a database Totally awesome, useful or just another pointless approach? Frank Celler, triAGENS, Cologne RuPy 2012, Brno 2012-11-16 www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 2. Agenda NoSQL database ArangoDB Use-Cases for actions mruby V8 or mruby? www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 3. NoSQL Databases Key/Value Store Document (Object) DB Graph Database www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 4. NoSQL Databases 2012-11-11: 150 DB on nosql-databases.org Key/Value Store Document (Object) DB Graph Database www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 5. NoSQL Databases 2012-11-11: 150 DB on nosql-databases.org Key/Value Store Document (Object) DB Graph Database Multi-Model Databases Polyglot Persistence www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 6. Multi-Model Open-Source Database Various Indexes: Skip-Lists, Hashes, Geo, Cap Language API/Drivers for big Ps, Ruby, JS Embedded JavaScript & Ruby engine Written in C/C++ Query Language for Joins and Sub-Structures www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 7. Query Language: FOR u in Users FOR u IN users LET rs = ( LET friends = ( FOR r in Recommendations FOR p in PATHS(user, relations, ``outbound´´, 1) FILTER r.rec_by == u._id && r.type == "Book" FILTER p._from == u._id RETURN r.book_title ) ) FILTER RETURN length(rs) >= 3 { user: u, closeFriends: friends } RETURN { "name" : u.name, "titles" : rs } (compare with UNQL / JSONiq) www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 8. Use-Cases for script languages GET /user/fceller function (req, res) { var user = db.users.byExample({ username: req.urlParameters.username }); ... deal with unknown user... enrich result user.age = ... compute user age from birthday ...; delete user.hashedPassword; actions.resultOk(req, res, actions.HTTP_OK, user); hide info } www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 9. Use-Cases for script languages GET /user/fceller/eccentricity function (req, res) { var user = db.users.byExample({ username: req.urlParameters.username }); ... deal with unknown user... needs every node var eccentricity = ... compute eccentricity ...; actions.resultOk(req, res, actions.HTTP_OK, eccentricity); } www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 10. Use-Cases for script languages Transactions Triggers Predefined Objects for AJAX www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 11. MRuby Matz's embeddable minimal implementation of Ruby language www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 12. MRuby RiteVM as core Minimal standard libraries quotes from Matz Embeddable C API No perfect languages, even Ruby Like to provide choices www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 13. MRuby vs V8 JavaScript is a “complicated” language for embedding C++ class hierarchies V8 itself is complex (isolates, contexts, handle scopes), but fast mruby is plain and simple C code documentation is sketchy for both www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 14. MRuby vs V8 def fact n; (n > 1) ? n*fact(n-1) : 1; end mruby: 20 time-units V8: 0.6 time-units php: 20 time-units Ruby 1.9 (int): 9 time-units www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 15. Why use MRuby? “Like to provide choices” i.e. if you don‘t like prototype inheritance “still young” i.e. instead of using RiteVM, compile to machine code www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 16. MRuby and LLVM def fact n; (n > 1) ? n*fact(n-1) : 1; end 000 OP_ENTER    1:0:0:0:0:0:0 001 OP_MOVE     R4      R1 002 OP_LOADI    R5      1 003 OP_LOADNIL  R6 004 OP_GT       R4      '>'     1 005 OP_JMPNOT   R4      017 006 OP_MOVE     R4      R1 007 OP_LOADSELF R5 008 OP_MOVE     R6      R1 009 OP_LOADI    R7      1 010 OP_LOADNIL  R8 011 OP_SUB      R6      '-'     1 012 OP_LOADNIL  R7 013 OP_SEND     R5      'fact' 1 014 OP_LOADNIL  R6 015 OP_MUL      R4      '*'     1 016 OP_JMP              018 017 OP_LOADI    R4      1 018 OP_RETURN   R4 www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 17. MRuby and LLVM CASE(OP_SUB) { /* A B C R(A) := R(A)-R(A+1) (Syms[B]=:-,C=1)*/ int a = GETARG_A(i); /* need to check if op is overridden */ switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): { mrb_int x, y, z; x = mrb_fixnum(regs[a]); y = mrb_fixnum(regs[a+1]); z = x - y; if (((x < 0) ^ (y < 0)) == 0 && (x < 0) != (z < 0)) { /* integer overflow */ SET_FLT_VALUE(regs[a], (mrb_float)x - (mrb_float)y); break; } SET_INT_VALUE(regs[a], z); } break; Simply replacing OP codes by machine code already gives a factor of 2 www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 18. Why use MRuby? If you have use-cases for scripts in ArangoDB (or any other database), mruby will eventually be an alternative Otherwise, use a language driver (aka Ashikawa for Ruby) and CRuby or JRuby www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12
  • 19. Thank You! Stay in Touch: Fork me on github Google Group: ArangoDB Twitter: @fceller & @arangodb www.arangodb.org www.arangodb.org (c) f.celler@triagens.de Mittwoch, 14. November 12