Running MRuby                            in a database               Totally awesome, useful or just another pointless app...
Agenda                           NoSQL database ArangoDB                           Use-Cases for actions                  ...
NoSQL Databases                    Key/Value Store                                 Document (Object) DB                   ...
NoSQL Databases                                               2012-11-11: 150 DB on                                       ...
NoSQL Databases                                                   2012-11-11: 150 DB on                                   ...
Multi-Model Open-Source Database                     Various Indexes: Skip-Lists, Hashes, Geo, Cap                     Lan...
Query Language:     FOR u in Users                                        FOR u IN users      LET rs = (                  ...
Use-Cases for                           script languages    GET /user/fceller    function (req, res) {      var user = db....
Use-Cases for                           script languages    GET /user/fceller/eccentricity    function (req, res) {      v...
Use-Cases for                           script languages                     Transactions                     Triggers    ...
MRuby                                    Matzs                                 embeddable                           minima...
MRuby                           RiteVM as core                           Minimal standard libraries                       ...
MRuby vs V8                           JavaScript is a “complicated” language for                           embedding C++ c...
MRuby vs V8                           def fact n; (n > 1) ? n*fact(n-1) : 1; end                             mruby: 20 tim...
Why use MRuby?                           “Like to provide choices”                             i.e. if you don‘t like prot...
MRuby and LLVM                           def fact n; (n > 1) ? n*fact(n-1) : 1; end                                   000 ...
MRuby and LLVM                           CASE(OP_SUB) {                             /* A B C R(A) := R(A)-R(A+1) (Syms[B]=...
Why use MRuby?                           If you have use-cases for scripts in                           ArangoDB (or any o...
Thank You!                 Stay in Touch:                      Fork me on github                      Google Group: Arango...
Upcoming SlideShare
Loading in...5
×

Using MRuby in a database

2,272

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,272
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
21
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Using MRuby in a database"

  1. 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.deSamstag, 17. November 12
  2. 2. Agenda NoSQL database ArangoDB Use-Cases for actions mruby V8 or mruby? www.arangodb.org (c) f.celler@triagens.deSamstag, 17. November 12
  3. 3. NoSQL Databases Key/Value Store Document (Object) DB Graph Database www.arangodb.org (c) f.celler@triagens.deSamstag, 17. November 12
  4. 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.deSamstag, 17. November 12
  5. 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.deSamstag, 17. November 12
  6. 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.deSamstag, 17. November 12
  7. 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.deSamstag, 17. November 12
  8. 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.deSamstag, 17. November 12
  9. 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.deSamstag, 17. November 12
  10. 10. Use-Cases for script languages Transactions Triggers Predefined Objects for AJAX www.arangodb.org (c) f.celler@triagens.deSamstag, 17. November 12
  11. 11. MRuby Matzs embeddable minimal implementation of Ruby language www.arangodb.org (c) f.celler@triagens.deSamstag, 17. November 12
  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.deSamstag, 17. November 12
  13. 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.deSamstag, 17. November 12
  14. 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.deSamstag, 17. November 12
  15. 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.deSamstag, 17. November 12
  16. 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.deSamstag, 17. November 12
  17. 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.deSamstag, 17. November 12
  18. 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.deSamstag, 17. November 12
  19. 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.deSamstag, 17. November 12
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×