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
Samstag, 17. November 12
Agenda


                           NoSQL database ArangoDB

                           Use-Cases for actions

                           mruby

                           V8 or mruby?



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


                    Key/Value Store                                 Document (Object) DB


                                            Graph Database




                                 www.arangodb.org (c) f.celler@triagens.de
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. November 12
Use-Cases for
                           script languages

                     Transactions

                     Triggers

                     Predefined Objects for AJAX




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

                                    Matz's
                                 embeddable
                           minimal implementation of
                                Ruby language



                             www.arangodb.org (c) f.celler@triagens.de
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. 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
Samstag, 17. November 12

Más contenido relacionado

La actualidad más candente

Query mechanisms for NoSQL databases
Query mechanisms for NoSQL databasesQuery mechanisms for NoSQL databases
Query mechanisms for NoSQL databasesArangoDB Database
 
FOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBArangoDB Database
 
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 WebinarArangoDB Database
 
Multi-model databases and node.js
Multi-model databases and node.jsMulti-model databases and node.js
Multi-model databases and node.jsMax Neunhöffer
 
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 webKurt Cagle
 
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 RelationshipsFabrizio Fortino
 
An introduction to Nosql
An introduction to NosqlAn introduction to Nosql
An introduction to Nosqlgreprep
 
Small Overview of Skype Database Tools
Small Overview of Skype Database ToolsSmall Overview of Skype Database Tools
Small Overview of Skype Database Toolselliando dias
 
Visualize your graph database
Visualize your graph databaseVisualize your graph database
Visualize your graph databaseMichael Hackstein
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabaseMubashar Iqbal
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databasesArangoDB Database
 
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() KWgmccarvell
 
State of the Semantic Web
State of the Semantic WebState of the Semantic Web
State of the Semantic WebIvan Herman
 
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.eross77
 
RDF SHACL, Annotations, and Data Frames
RDF SHACL, Annotations, and Data FramesRDF SHACL, Annotations, and Data Frames
RDF SHACL, Annotations, and Data FramesKurt Cagle
 
Graph Databases & OrientDB
Graph Databases & OrientDBGraph Databases & OrientDB
Graph Databases & OrientDBArpit Poladia
 
ODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLMarco Gralike
 
Introduction to RDFa
Introduction to RDFaIntroduction to RDFa
Introduction to RDFaIvan Herman
 

La actualidad más candente (20)

Query mechanisms for NoSQL databases
Query mechanisms for NoSQL databasesQuery mechanisms for NoSQL databases
Query mechanisms for NoSQL databases
 
FOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDBFOXX - a Javascript application framework on top of ArangoDB
FOXX - a Javascript application framework on top of ArangoDB
 
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
 
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
 
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
 
An introduction to Nosql
An introduction to NosqlAn introduction to Nosql
An introduction to Nosql
 
Small Overview of Skype Database Tools
Small Overview of Skype Database ToolsSmall Overview of Skype Database Tools
Small Overview of Skype Database Tools
 
Visualize your graph database
Visualize your graph databaseVisualize your graph database
Visualize your graph database
 
PostgreSQL - Object Relational Database
PostgreSQL - Object Relational DatabasePostgreSQL - Object Relational Database
PostgreSQL - Object Relational Database
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databases
 
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
 
State of the Semantic Web
State of the Semantic WebState of the Semantic Web
State of the Semantic Web
 
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.
 
RDF SHACL, Annotations, and Data Frames
RDF SHACL, Annotations, and Data FramesRDF SHACL, Annotations, and Data Frames
RDF SHACL, Annotations, and Data Frames
 
RDFa Tutorial
RDFa TutorialRDFa Tutorial
RDFa Tutorial
 
Graph Databases & OrientDB
Graph Databases & OrientDBGraph Databases & OrientDB
Graph Databases & OrientDB
 
ODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XMLODTUG Webcast - Thinking Clearly about XML
ODTUG Webcast - Thinking Clearly about XML
 
NHibernate
NHibernateNHibernate
NHibernate
 
Introduction to RDFa
Introduction to RDFaIntroduction to RDFa
Introduction to RDFa
 

Similar a Using MRuby in a database

RDF APIs for .NET Framework
RDF APIs for .NET FrameworkRDF APIs for .NET Framework
RDF APIs for .NET FrameworkAdriana Ivanciu
 
Publishing RDF SKOS with microservices
Publishing RDF SKOS with microservicesPublishing RDF SKOS with microservices
Publishing RDF SKOS with microservicesBart Hanssens
 
Graph databases & data integration v2
Graph databases & data integration v2Graph databases & data integration v2
Graph databases & data integration v2Dimitris Kontokostas
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)javier ramirez
 
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 pandasWes McKinney
 
Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Slides 111017220255-phpapp01
Slides 111017220255-phpapp01Ken Mwai
 
Thinking in documents
Thinking in documentsThinking in documents
Thinking in documentsCésar Rodas
 
Polyglot persistence for Java developers - moving out of the relational comfo...
Polyglot persistence for Java developers - moving out of the relational comfo...Polyglot persistence for Java developers - moving out of the relational comfo...
Polyglot persistence for Java developers - moving out of the relational comfo...Chris Richardson
 
Riak intro to..
Riak intro to..Riak intro to..
Riak intro to..Adron Hall
 
Extending lifespan with Hadoop and R
Extending lifespan with Hadoop and RExtending lifespan with Hadoop and R
Extending lifespan with Hadoop and RRadek Maciaszek
 
Basics of Metaprogramming in Ruby
Basics of Metaprogramming in RubyBasics of Metaprogramming in Ruby
Basics of Metaprogramming in RubyDigital Natives
 
SparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on HadoopSparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on HadoopDataWorks Summit
 

Similar a Using MRuby in a database (20)

Introduction to dotNetRDF
Introduction to dotNetRDFIntroduction to dotNetRDF
Introduction to dotNetRDF
 
StORM preview
StORM previewStORM preview
StORM preview
 
RDF APIs for .NET Framework
RDF APIs for .NET FrameworkRDF APIs for .NET Framework
RDF APIs for .NET Framework
 
Bentobox exercise
Bentobox exerciseBentobox exercise
Bentobox exercise
 
Publishing RDF SKOS with microservices
Publishing RDF SKOS with microservicesPublishing RDF SKOS with microservices
Publishing RDF SKOS with microservices
 
Graph databases & data integration v2
Graph databases & data integration v2Graph databases & data integration v2
Graph databases & data integration v2
 
No Sql
No SqlNo Sql
No Sql
 
Your Database Cannot Do this (well)
Your Database Cannot Do this (well)Your Database Cannot Do this (well)
Your Database Cannot Do this (well)
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
Nosql and newsql
Nosql and newsqlNosql and newsql
Nosql and newsql
 
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
 
Thinking in documents
Thinking in documentsThinking in documents
Thinking in documents
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
Spark training-in-bangalore
Spark training-in-bangaloreSpark training-in-bangalore
Spark training-in-bangalore
 
Polyglot persistence for Java developers - moving out of the relational comfo...
Polyglot persistence for Java developers - moving out of the relational comfo...Polyglot persistence for Java developers - moving out of the relational comfo...
Polyglot persistence for Java developers - moving out of the relational comfo...
 
Riak intro to..
Riak intro to..Riak intro to..
Riak intro to..
 
Extending lifespan with Hadoop and R
Extending lifespan with Hadoop and RExtending lifespan with Hadoop and R
Extending lifespan with Hadoop and R
 
Basics of Metaprogramming in Ruby
Basics of Metaprogramming in RubyBasics of Metaprogramming in Ruby
Basics of Metaprogramming in Ruby
 
SparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on HadoopSparkR: Enabling Interactive Data Science at Scale on Hadoop
SparkR: Enabling Interactive Data Science at Scale on Hadoop
 

Más de ArangoDB Database

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)....ArangoDB Database
 
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/2022ArangoDB Database
 
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/2022ArangoDB Database
 
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 ScaleArangoDB Database
 
GraphSage vs Pinsage #InsideArangoDB
GraphSage vs Pinsage #InsideArangoDBGraphSage vs Pinsage #InsideArangoDB
GraphSage vs Pinsage #InsideArangoDBArangoDB Database
 
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 ArangoDB Database
 
Graph Analytics with ArangoDB
Graph Analytics with ArangoDBGraph Analytics with ArangoDB
Graph Analytics with ArangoDBArangoDB Database
 
Getting Started with ArangoDB Oasis
Getting Started with ArangoDB OasisGetting Started with ArangoDB Oasis
Getting Started with ArangoDB OasisArangoDB Database
 
Custom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBCustom Pregel Algorithms in ArangoDB
Custom Pregel Algorithms in ArangoDBArangoDB Database
 
Hacktoberfest 2020 - Intro to Knowledge Graphs
Hacktoberfest 2020 - Intro to Knowledge GraphsHacktoberfest 2020 - Intro to Knowledge Graphs
Hacktoberfest 2020 - Intro to Knowledge GraphsArangoDB Database
 
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?ArangoDB Database
 
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 MetadataArangoDB Database
 
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 ScaleArangoDB Database
 
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 OasisArangoDB Database
 
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, 2019ArangoDB Database
 
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 ArangoDBArangoDB Database
 
An introduction to multi-model databases
An introduction to multi-model databasesAn introduction to multi-model databases
An introduction to multi-model databasesArangoDB Database
 
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 systemArangoDB Database
 
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?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?
 

Using MRuby in a database

  • 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 Samstag, 17. November 12
  • 2. Agenda NoSQL database ArangoDB Use-Cases for actions mruby V8 or mruby? www.arangodb.org (c) f.celler@triagens.de Samstag, 17. November 12
  • 3. NoSQL Databases Key/Value Store Document (Object) DB Graph Database www.arangodb.org (c) f.celler@triagens.de Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. November 12
  • 10. Use-Cases for script languages Transactions Triggers Predefined Objects for AJAX www.arangodb.org (c) f.celler@triagens.de Samstag, 17. November 12
  • 11. MRuby Matz's embeddable minimal implementation of Ruby language www.arangodb.org (c) f.celler@triagens.de Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. 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 Samstag, 17. November 12