Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Running MRuby in a database - Totally awesome, useful or just another pointless approach
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
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
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