Константин Осипов (Mail.Ru)

  • Upload
    ontico

  • View
    2.317

  • Download
    0

Embed Size (px)

Citation preview

Tarantool 1.6 Primer

++, 2014Konstantin Osipov

Tarantool?

Redis + Node.JS Lua

multipart

, , ,

1.6

AppServer:

MsgPack

Lua LuaFFI :

-

Lua application server

/ callbacks

( )

Lua

#! (hashbang)

c, http , , ...

AppServer

#!/usr/bin/env tarantool

#!/usr/bin/env tarantoolbox.cfg{admin_port=3313} - start databases = box.schema.create_space('s', { if_not_exists = true})if not s.index.primary s:create_index('primary', { type = 'hash' })endlocal purger = box.fiber.wrap(function() end)local sock = require('box.socket').tcp()sock:connect()

Data dictionary

cluster & sharding friendly box.schema.create_space()box.schema.create_user()box.schema.create_function()_space, _function, _user system spaces

MsgPack

BSON,

schema-less

~30% Tarantool 1.5

as-is

Tarantool MsgPack

MsgPack

space:insert{1, 'online', { atime = box.time(), referer = 'rit++'}}---- [1, 'online', {'atime': 1396161275.7198, 'referer': 'rit++'}]...0x960102A45465737483A26B3330A26B31A27631A26B32930A0F14C3CB400921CAC083126F

Discretional Access Control model

,

Guest Admin users

Spaces, Functions and the Universebox.schema.user.create('kostja')box.schema.user.grant('kostja', 'read,write,execute', 'universe')

Lua

Tracing just-in-time compiler Foreign Function Interface

JIT select(), map(), filter()

v8

Tarantool + LuaJIT = C

: tracing JIT

x = tabulate(math.sin) :take(100) :map(function(x) return x^2 end) :sum()=> => 12 ASM

space:iterator(...) :map(...) :filter(...) :reduce(...) ...

=>> LOOP: 0bcaffd0 movsd [rsp+0x8], xmm7 0bcaffd6 addsd xmm4, xmm5 0bcaffda ucomisd xmm6, xmm1 0bcaffde jnb 0x0bca0028 ->6 0bcaffe4 addsd xmm6, xmm0 0bcaffe8 addsd xmm7, xmm0 0bcaffec fld qword [rsp+0x8] 0bcafff0 fsin 0bcafff2 fstp qword [rsp] 0bcafff5 movsd xmm5, [rsp] 0bcafffa mulsd xmm5, xmm5 0bcafffe jmp 0x0bcaffd0 ->LOOP ---- TRACE 1 stop -> loop

-

, failover

first> space:replace{1, 'hello'}--- [1, 'hello']... second> space:replace{2, 'world'}---- [2, 'world']...

: -

first> space:select{}---- [1, 'hello']- [2, 'world']...second> space:select{}---- [1, 'hello']- [2, 'world']...

,

Sophia engine LevelDB

SSD

mem / disk Web

Tarantoolbox.schema.create_space('archive', { engine = 'sophia'})

Sophia:

Key-value index

Disk

10, 25

Memory

15264084Page index

Disk

26, 3110, 15, 16, 2539, 40, 84, 85split

26, 3186, 9639, 8586, 96

lock-free

wait-free

yield()

1 Lua = 1

Q&A

http://tarantool.org/
https://github.com/tarantool