Ho Tarantool, o ka kopanya database e potlakileng haholo le sesebelisoa sa ho sebetsa le bona. Mona ke kamoo ho leng bonolo ho e etsa

Lilemong tse hlano tse fetileng ke ile ka leka ho sebetsa le Tarantool, empa joale ha ea ka ea nthusa. Empa haufinyane tjena ke ile ka tšoara webinar moo ke buileng ka Hadoop, mabapi le hore na MapReduce e sebetsa joang. Ha ke le moo ke ile ka botsoa potso - "Hobaneng u sa sebelise Tarantool bakeng sa mosebetsi oo?".

Ka lebaka la bohelehele, ke ile ka etsa qeto ea ho khutlela ho eona, ho leka phetolelo ea morao-rao - 'me lekhetlong lena ke ratile morero ona haholo. Hona joale ke tla bontša mokhoa oa ho ngola kopo e bonolo ho Tarantool, ho e laela le ho hlahloba tshebetso, 'me u tla bona kamoo ntho e' ngoe le e 'ngoe e leng bonolo le e pholileng kateng moo.

Ho Tarantool, o ka kopanya database e potlakileng haholo le sesebelisoa sa ho sebetsa le bona. Mona ke kamoo ho leng bonolo ho e etsa

Tarantool ke eng

Tarantool e ipeha e le database e potlakileng haholo. U ka kenya data efe kapa efe eo u e batlang moo. Hape, li phete, shard - ke hore, arola palo e kholo ea data ho li-server tse 'maloa' me u kopanye liphetho tse tsoang ho tsona - etsa lihokelo tsa master-master tse mamellang liphoso.

Ea bobeli, ke seva sa kopo. O ka ngola lits'ebetso tsa hau ho eona, sebetsa ka data, ho etsa mohlala, hlakola likhakanyo tsa khale ka morao ho latela melao e itseng. U ka ngola seva sa Http ka kotloloho ho Tarantula e tla sebetsa le data: fana ka nomoro ea bona, ngola lintlha tse ncha moo 'me u li fokotse kaofela ho monghali.

Ke balile sengoloa se buang ka hore na bashanyana ba entse mola oa mela e 300 joang, e leng meokho le meokho feela - ba na le ts'ebetso e fokolang ea melaetsa ea 20 motsotsoana. Mona o ka reteleha 'me oa ngola ts'ebeliso e kholo haholo,' me tsena li ke ke tsa bolokoa, joalo ka PostgreS.

Hoo e ka bang seva e joalo, e bonolo feela, ke tla leka ho e hlalosa sehloohong sena.

bophirima

Bakeng sa tlhahlobo, ke ile ka qala mechini e meraro e tloaelehileng - hard drive ea 20 gigabyte, Ubuntu 18.04. 2 virtual CPU le 4 gigabytes ea memori.

Re kenya Tarantool - tsamaisa sengoloa sa bash kapa eketsa polokelo 'me u ka fumana Tarantool hantle. Khokahanyo ea mongolo - (curl -L https://tarantool.io/installer.sh | VER=2.4 sudo -E bash). Re na le litaelo tse kang:

tarantoolctl ke taelo e kholo ea ho laola maemo a Tarantula.
/etc/tarantool - Mona ho na le tlhophiso eohle.
var/log/tarantool - mona ke lifate.
var/lib/tarantool - mona ho na le lintlha, ebe li aroloa ka maemo.

Ho na le lifoldara tse fumanehang ka mohlala le tse nolofalletsang mohlala - e na le se tla hlahisoa - faele ea tlhophiso ea mohlala e nang le khoutu ea lua, e hlalosang hore na e mamela likou life, ke mohopolo ofe o teng ho eona, litlhophiso tsa enjine ea Vinyl, khoutu e sebetsang qalong. li-server, ho sharding, mela, ho hlakoloa ha data e sa sebetseng, joalo-joalo.

Maemo a sebetsa joalo ka PostgreS. Mohlala, o batla ho tsamaisa likopi tse ngata tsa database tse leketlileng likoung tse fapaneng. Hoa fumaneha hore liketsahalo tse 'maloa tsa database li hlahisoa ho seva se le seng, se leketlileng likoung tse fapaneng. Li ka ba le litlhophiso tse fapaneng ka ho felletseng - mohlala o le mong o sebelisa mohopolo o le mong, oa bobeli - o mong.

Tsamaiso ea maemo

Re na le taelo ea tarantoolctl e re lumellang ho laola maemo a Tarantula. Mohlala, mohlala oa tlhahlobo ea tarantoolctl o tla hlahloba faele ea tlhophiso mme o re faele e lokile haeba ho se na liphoso tsa syntax.

U ka bona boemo ba mohlala - mohlala oa boemo ba tarantoolctl. Ka mokhoa o ts'oanang, o ka qala, emisa, qala bocha.

Hang ha mohlala o sebetsa, ho na le mekhoa e 'meli ea ho hokela ho eona.

1. Tsamaiso ea tsamaiso

Ka mokhoa o ikhethileng, Tarantool e bula sokete ebe e romela mongolo o hlakileng oa ASCII ho laola Tarantula. Khokahano ho console e lula e etsahala tlasa mosebelisi oa admin, ha ho na netefatso, ka hona ha ho hlokahale hore u ntše koung ea console ho laola Tarantula kantle.

Ho hokela ka tsela ena, o hloka ho kenya Tarantoolctl kenya lebitso la mohlala. Taelo e tla qala console ebe e hokela joalo ka mosebelisi oa admin. Le ka mohla u se ke ua pepesa koung ea console ka ntle - ho molemo ho e tlohela e le sokete ea yuniti. Joale ke ba nang le phihlelo ea ho ngola feela ba tla khona ho hokahanya le Tarantula.

Mokhoa ona oa hlokahala bakeng sa lintho tsa tsamaiso. Ho sebetsa le data, sebelisa mokhoa oa bobeli - protocol ea binary.

2. Ho sebelisa protocol ea binary ho hokahanya le koung e itseng

Ho na le taelo ea ho mamela ho tlhophiso, e bulang boema-kepe bakeng sa likhokahano tsa kantle. Boema-kepe bona bo sebelisoa ka protocol ea binary mme netefatso e ea lumelloa moo.

Bakeng sa khokahano ena, tarantoolctl hokela ho nomoro ea boema-kepe e sebelisoa. U e sebelisa, u ka hokela ho li-server tse hole, sebelisa netefatso le ho fana ka litokelo tse fapaneng tsa phihlello.

Ho rekota data le Module oa Lebokose

Kaha Tarantool ke database le seva sa kopo, e na le li-module tse fapaneng. Re thahasella mojule oa lebokose - e sebelisa mosebetsi ka data. Ha u ngolla ntho e itseng lebokoseng, Tarantool e ngola data ho disk, e e boloka mohopolong, kapa e etsa ntho e 'ngoe ka eona.

Ho rekota

Ka mohlala, re kena ka har'a mojule oa lebokose ebe re letsetsa lebokose. E tla qobella Tarantool ho tsamaisa khoutu ea rona ha seva e qala. Re theha sebaka moo data ea rona e tla bolokoa teng.

local function bootstrap()
    local space = box.schema.create_space('example')
    space:create_index('primary')
    box.schema.user.grant('guest', 'read,write,execute', 'universe')

    -- Keep things safe by default
    --  box.schema.user.create('example', { password = 'secret' })
    --  box.schema.user.grant('example', 'replication')
    --  box.schema.user.grant('example', 'read,write,execute', 'space', 'example')
end

Kamora moo, re theha index ea mantlha - ea mantlha - eo ka eona re ka batlang data. Ka ho sa feleng, haeba ho se na li-parameter tse boletsoeng, ho tla sebelisoa sebaka sa pele sa ntlha e 'ngoe le e 'ngoe bakeng sa index ea pele.

Ebe re fana ka thuso ho mosebelisi oa moeti, eo tlas'a eona re hokahanyang ka protocol ea binary. Re lumella ho bala, ho ngola le ho phethahatsa ketsahalong eohle.

Ha ho bapisoa le li-database tse tloaelehileng, tsohle li bonolo haholo mona. Re na le sebaka - sebaka seo data ea rona e bolokiloeng ho sona feela. Keno ka 'ngoe e bitsoa tuple. E phuthetsoe ka har'a MessagePack. Ena ke sebopeho se pholileng haholo - ke sa binary 'me se nka sebaka se senyenyane - 18 bytes khahlano le 27.

Ho Tarantool, o ka kopanya database e potlakileng haholo le sesebelisoa sa ho sebetsa le bona. Mona ke kamoo ho leng bonolo ho e etsa

Ho bonolo haholo ho sebetsa le eena. Hoo e ka bang mohala o mong le o mong, keno e 'ngoe le e' ngoe ea data e ka ba le likholomo tse fapaneng ka ho felletseng.

Re ka sheba libaka tsohle ka ho sebelisa taelo ea Box.space. Ho khetha mohlala o itseng, re ngola mohlala oa box.space ebe re fumana lintlha tse felletseng ho eona.

Ho na le mefuta e 'meli ea lienjineri tse hahiloeng ho Tarantool: Memory le Vinyl. Memori e boloka data eohle mohopolong. Ka hona, ntho e 'ngoe le e' ngoe e sebetsa ka mokhoa o bonolo le ka potlako. Lintlha li lahleloa ho disk, hape ho na le mochine oa ho ngola pele, kahoo re ke ke ra lahleheloa ke letho haeba seva se senyeha.

Vinyl e boloka data ho disk ka mokhoa o tloaelehileng - ke hore, o ka boloka lintlha tse ngata ho feta tseo re li hopolang, 'me Tarantula e tla e bala ho tswa ho disk.

Joale re tla sebelisa Memori.

unix/:/var/run/tarantool/example.control> box.space.example
---
- engine: memtx
  before_replace: 'function: 0x41eb02c8'
  on_replace: 'function: 0x41eb0568'
  ck_constraint: []
  field_count: 0
  temporary: false
  index:
    0: &0
      unique: true
      parts:
      - type: unsigned
        is_nullable: false
        fieldno: 1
      id: 0
      space_id: 512
      type: TREE
      name: primary
    primary: *0
  is_local: false
  enabled: true
  name: example
  id: 512
...

unix/:/var/run/tarantool/example.control>

Index:

Index ea mantlha e tlameha ho etsoa bakeng sa sebaka leha e le sefe, hobane ha ho letho le tla sebetsa ntle le lona. Joalo ka polokelong efe kapa efe, re theha tšimo ea pele - ID ea rekoto.

Likarolo:

Mona ke moo re hlakisang hore na index ea rona e na le eng. E na le karolo e le 'ngoe - sebaka sa pele seo re tla se sebelisa, thaepa e sa saena - palo e feletseng. Ho ea kamoo ke hopolang ka litokomane, palo e kholo e ka bang 18 quintillion. Tse ngata tse makatsang.

Joale re ka kenya data re sebelisa taelo ea ho kenya.

unix/:/var/run/tarantool/example.control> box.space.example:insert{1, 'test1', 'test2'}
---
- [1, 'test1', 'test2']
...

unix/:/var/run/tarantool/example.control> box.space.example:insert{2, 'test2', 'test3', 'test4'}
---
- [2, 'test2', 'test3', 'test4']
...

unix/:/var/run/tarantool/example.control> box.space.example:insert{3, 'test3'}
---
- [3, 'test3']
...

unix/:/var/run/tarantool/example.control> box.space.example:insert{4, 'test4'}
---
- [4, 'test4']
...

unix/:/var/run/tarantool/example.control>

Tšimo ea pele e sebelisoa e le senotlolo sa mantlha, kahoo e tlameha ho ikhetha. Ha re na moeli ke palo ea litšiea, kahoo re ka kenya data e ngata kamoo re ratang kateng moo. Li hlalositsoe ka mokhoa oa MessagePack, oo ke o hlalositseng ka holimo.

Tlhahiso ea data

Joale re ka bonts'a data ka khetho ea taelo.

Box.example.select ka konopo {1} e tla hlahisa seo u se batlang. Haeba re siea senotlolo, re tla bona lirekoto tsohle tseo re nang le tsona. Kaofela li fapane ka palo ea litšiea, empa mona, ha e le hantle, ha ho na maikutlo a litšiea - ho na le linomoro tsa tšimo.

Ho ka ba le data e ngata kamoo u ratang. 'Me ka mohlala, re hloka ho li batla tšimong ea bobeli. Ho etsa sena, re etsa index e ncha ea bobeli.


box.space.example:create_index( ‘secondary’, { type = ‘TREE’, unique = false, parts = {{field = 2, type =’string’} }}) 

Re sebelisa taelo ea Create_index.
Re e bitsa Secondary.

Ka mor'a moo, o hloka ho totobatsa li-parameter. Mofuta oa index ke TREE. E ka 'na ea se ke ea ikhetha, kahoo re kena Unique = bohata.

Ebe joale re bontša hore na index ea rona e na le likarolo life. Tšimo ke palo ea tšimo eo re tlamang index ho eona, 'me e hlalosa mofuta oa khoele. 'Me kahoo e ile ea bōptjoa.

unix/:/var/run/tarantool/example.control> box.space.example:create_index('secondary', { type = 'TREE', unique = false, parts = {{field = 2, type = 'string'}}})
---
- unique: false
  parts:
  - type: string
    is_nullable: false
    fieldno: 2
  id: 1
  space_id: 512
  type: TREE
  name: secondary
...

unix/:/var/run/tarantool/example.control>

Joale re ka e bitsa tjena:

unix/:/var/run/tarantool/example.control> box.space.example.index.secondary:select('test1')
---
- - [1, 'test1', 'test2']
...

Ho boloka

Haeba re qala mohlala hape mme re leka ho letsetsa data hape, re tla bona hore ha e eo - tsohle ha li na letho. Sena se etsahala hobane Tarantool e etsa li-checkpoints 'me e boloka data ho disk, empa haeba re khaotsa ho sebetsa pele ho boloka ho latelang, re tla lahleheloa ke mesebetsi eohle - hobane re tla hlaphoheloa ho tloha sebakeng sa ho qetela sa ho hlahloba, se neng se le, ka mohlala, lihora tse peli tse fetileng.

Ho boloka motsotsoana o mong le o mong le hona ho ke ke ha sebetsa - hobane kamehla ho lahlela 20 GB ho disk ke mohopolo o joalo.

Bakeng sa sena, mohopolo oa ho ngola-pele o ile oa qaptjoa 'me oa kenngoa ts'ebetsong. Ka thuso ea eona, bakeng sa phetoho e 'ngoe le e' ngoe ea data, rekoto e etsoa ka faele e nyenyane ea ho ngola-pele.

E 'ngoe le e' ngoe e kenang sebakeng sa tlhahlobo e bolokiloe ho tsona. Bakeng sa lifaele tsena, re beha boholo - ka mohlala, 64 mb. Ha e tlatsa, ho rekota ho qala ho ea faeleng ea bobeli. 'Me ka mor'a ho qala bocha, Tarantool e hlaphoheloa ho tloha sebakeng sa ho qetela sa tlhahlobo ebe e theola litšebelisano tsohle tsa morao-rao ho fihlela e emisa.

Ho Tarantool, o ka kopanya database e potlakileng haholo le sesebelisoa sa ho sebetsa le bona. Mona ke kamoo ho leng bonolo ho e etsa

Ho etsa rekoto e joalo, o hloka ho hlakisa khetho ho li-setting tsa box.cfg (ho mohlala.lua faele):

wal_mode = “write”;

tshebediso ya data

Ka seo re se ngotseng hona joale, u ka sebelisa Tarantula ho boloka data 'me e tla sebetsa ka potlako e le database. 'Me joale ciliegia holim'a kaka - u ka etsa'ng ka eona kaofela.

Ho ngola kopo

Ka mohlala, a re ngoleng kopo e joalo bakeng sa Tarantula

Sheba kopo tlas'a spoiler

box.cfg {
    listen = '0.0.0.0:3301';
    io_collect_interval = nil;
    readahead = 16320;
    memtx_memory = 128 * 1024 * 1024; -- 128Mb
    memtx_min_tuple_size = 16;
    memtx_max_tuple_size = 128 * 1024 * 1024; -- 128Mb
    vinyl_memory = 128 * 1024 * 1024; -- 128Mb
    vinyl_cache = 128 * 1024 * 1024; -- 128Mb
    vinyl_max_tuple_size = 128 * 1024 * 1024; -- 128Mb
    vinyl_write_threads = 2;
    wal_mode = "write";
    wal_max_size = 256 * 1024 * 1024;
    checkpoint_interval = 60 * 60; -- one hour
    checkpoint_count = 6;
    force_recovery = true;
    log_level = 5;
    log_nonblock = false;
    too_long_threshold = 0.5;
    read_only   = false
}

local function bootstrap()
    local space = box.schema.create_space('example')
    space:create_index('primary')

    box.schema.user.create('example', { password = 'secret' })
    box.schema.user.grant('example', 'read,write,execute', 'space', 'example')

    box.schema.user.create('repl', { password = 'replication' })
    box.schema.user.grant('repl', 'replication')
end

-- for first run create a space and add set up grants
box.once('replica', bootstrap)

-- enabling console access
console = require('console')
console.listen('127.0.0.1:3302')

-- http config
local charset = {}  do -- [0-9a-zA-Z]
    for c = 48, 57  do table.insert(charset, string.char(c)) end
    for c = 65, 90  do table.insert(charset, string.char(c)) end
    for c = 97, 122 do table.insert(charset, string.char(c)) end
end

local function randomString(length)
    if not length or length <= 0 then return '' end
    math.randomseed(os.clock()^5)
    return randomString(length - 1) .. charset[math.random(1, #charset)]
end

local http_router = require('http.router')
local http_server = require('http.server')
local json = require('json')

local httpd = http_server.new('0.0.0.0', 8080, {
    log_requests = true,
    log_errors = true
})

local router = http_router.new()

local function get_count()
 local cnt = box.space.example:len()
 return cnt
end

router:route({method = 'GET', path = '/count'}, function()
    return {status = 200, body = json.encode({count = get_count()})}
end)

router:route({method = 'GET', path = '/token'}, function()
    local token = randomString(32)
    local last = box.space.example:len()
    box.space.example:insert{ last + 1, token }
    return {status = 200, body = json.encode({token = token})}
end)

prometheus = require('prometheus')

fiber = require('fiber')
tokens_count = prometheus.gauge("tarantool_tokens_count",
                              "API Tokens Count")

function monitor_tokens_count()
  while true do
    tokens_count:set(get_count())
    fiber.sleep(5)
  end
end
fiber.create(monitor_tokens_count)

router:route( { method = 'GET', path = '/metrics' }, prometheus.collect_http)

httpd:set_router(router)
httpd:start()

Re phatlalatsa tafole e itseng ka lua e hlalosang matšoao. Tafole ena ea hlokahala ho hlahisa khoele e sa reroang.

local charset = {}  do -- [0-9a-zA-Z]
    for c = 48, 57  do table.insert(charset, string.char(c)) end
    for c = 65, 90  do table.insert(charset, string.char(c)) end
    for c = 97, 122 do table.insert(charset, string.char(c)) end
end

Ka mor'a moo, re phatlalatsa mosebetsi - randomString mme re fana ka boleng ba bolelele ka har'a masaka.

local function randomString(length)
    if not length or length <= 0 then return '' end
    math.randomseed(os.clock()^5)
    return randomString(length - 1) .. charset[math.random(1, #charset)]
end

Ebe re kopanya http router le http seva ho seva sa rona sa Tarantula, JSON, seo re tla se fa mofani.

local http_router = require('http.router')
local http_server = require('http.server')
local json = require('json')

Ka mor'a moo, re qala ho port 8080 ho li-interfaces tsohle tsa http, tse tla kenya likōpo le liphoso tsohle.

local httpd = http_server.new('0.0.0.0', 8080, {
    log_requests = true,
    log_errors = true
})

Ka mor'a moo, re phatlalatsa tsela eo haeba kopo e nang le mokhoa oa GET e fihla ho port 8080 / count, joale re bitsa mosebetsi ho tloha moleng o le mong. E khutlisetsa boemo - 200, 404, 403 kapa eng kapa eng eo re e hlalosang.

router:route({method = 'GET', path = '/count'}, function()
    return {status = 200, body = json.encode({count = get_count()})}
end)

'Meleng, re khutlisetsa json.encode, re hlalosa palo le getcount ho eona, e bitsoang le ho bontša palo ea lirekoto ho database ea rona.

Tsela ea bobeli

router:route({method = 'GET', path = '/token'}, function() 
    local token = randomString(32) 
    local last = box.space.example:len() 
    box.space.example:insert{ last + 1, token } 
    return {status = 200, body = json.encode({token = token})}
end)

Moo moleng router: tsela({mokgwa = 'GET', tsela = '/letshwao'}, tshebetso() re bitsa tshebetso mme re hlahisa letshwao.

Lintja letshwao la lehae = randomString(32) ke khoele e sa reroang ea litlhaku tse 32.
E mocheng local last = box.space.example:len() re ntša element ea ho qetela.
Le moleng box.space.example:insert{ last + 1, token } re ngola data ho database ea rona, ke hore, re eketsa ID feela ka 1. Sena se ka etsoa, ​​ka tsela, eseng feela ka tsela e joalo e makatsang. Tarantula e na le tatellano ea nyeoe ena.

Re ngola letshwao moo.

Kahoo, re ngotse kopo faeleng e le 'ngoe. U ka fihlella data hang-hang, 'me module ea lebokose e tla u etsetsa mosebetsi o litšila.

E mamela http mme e sebetsa ka data, ntho e 'ngoe le e' ngoe e le ketsahalong e le 'ngoe - kopo le data. Ka hona, ntho e 'ngoe le e' ngoe e etsahala ka potlako.

Ho matha, re kenya http module:

Kamoo re e etsang, bona tlas'a senya

root@test2:/# tarantoolctl rocks install http
Installing http://rocks.tarantool.org/http-scm-1.src.rock
Missing dependencies for http scm-1:
   checks >= 3.0.1 (not installed)

http scm-1 depends on checks >= 3.0.1 (not installed)
Installing http://rocks.tarantool.org/checks-3.0.1-1.rockspec

Cloning into 'checks'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 28 (delta 1), reused 16 (delta 1), pack-reused 0
Receiving objects: 100% (28/28), 12.69 KiB | 12.69 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Note: checking out '580388773ef11085015b5a06fe52d61acf16b201'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

No existing manifest. Attempting to rebuild...
checks 3.0.1-1 is now installed in /.rocks (license: BSD)

-- The C compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found TARANTOOL: /usr/include (found version "2.4.2-80-g18f2bc82d")
-- Tarantool LUADIR is /.rocks/share/tarantool/rocks/http/scm-1/lua
-- Tarantool LIBDIR is /.rocks/share/tarantool/rocks/http/scm-1/lib
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    version


-- Build files have been written to: /tmp/luarocks_http-scm-1-V4P9SM/http/build.luarocks
Scanning dependencies of target httpd
[ 50%] Building C object http/CMakeFiles/httpd.dir/lib.c.o
In file included from /tmp/luarocks_http-scm-1-V4P9SM/http/http/lib.c:32:0:
/tmp/luarocks_http-scm-1-V4P9SM/http/http/lib.c: In function ‘tpl_term’:
/usr/include/tarantool/lauxlib.h:144:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
    (*(B)->p++ = (char)(c)))
    ~~~~~~~~~~~^~~~~~~~~~~~
/tmp/luarocks_http-scm-1-V4P9SM/http/http/lib.c:62:7: note: in expansion of macro ‘luaL_addchar’
       luaL_addchar(b, '\');
       ^~~~~~~~~~~~
/tmp/luarocks_http-scm-1-V4P9SM/http/http/lib.c:63:6: note: here
      default:
      ^~~~~~~
In file included from /tmp/luarocks_http-scm-1-V4P9SM/http/http/lib.c:39:0:
/tmp/luarocks_http-scm-1-V4P9SM/http/http/tpleval.h: In function ‘tpe_parse’:
/tmp/luarocks_http-scm-1-V4P9SM/http/http/tpleval.h:147:9: warning: this statement may fall through [-Wimplicit-fallthrough=]
    type = TPE_TEXT;
    ~~~~~^~~~~~~~~~
/tmp/luarocks_http-scm-1-V4P9SM/http/http/tpleval.h:149:3: note: here
   case TPE_LINECODE:
   ^~~~
In file included from /tmp/luarocks_http-scm-1-V4P9SM/http/http/lib.c:40:0:
/tmp/luarocks_http-scm-1-V4P9SM/http/http/httpfast.h: In function ‘httpfast_parse’:
/tmp/luarocks_http-scm-1-V4P9SM/http/http/httpfast.h:372:22: warning: this statement may fall through [-Wimplicit-fallthrough=]
                 code = 0;
                 ~~~~~^~~
/tmp/luarocks_http-scm-1-V4P9SM/http/http/httpfast.h:374:13: note: here
             case status:
             ^~~~
/tmp/luarocks_http-scm-1-V4P9SM/http/http/httpfast.h:393:23: warning: this statement may fall through [-Wimplicit-fallthrough=]
                 state = message;
                 ~~~~~~^~~~~~~~~
/tmp/luarocks_http-scm-1-V4P9SM/http/http/httpfast.h:395:13: note: here
             case message:
             ^~~~
[100%] Linking C shared library lib.so
[100%] Built target httpd
[100%] Built target httpd
Install the project...
-- Install configuration: "Debug"
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/VERSION.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lib/http/lib.so
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/server/init.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/server/tsgi_adapter.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/nginx_server/init.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/router/init.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/router/fs.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/router/matching.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/router/middleware.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/router/request.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/router/response.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/tsgi.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/utils.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/mime_types.lua
-- Installing: /.rocks/share/tarantool/rocks/http/scm-1/lua/http/codes.lua
http scm-1 is now installed in /.rocks (license: BSD)

root@test2:/#

Re boetse re hloka prometheus ho sebetsa:

root@test2:/# tarantoolctl rocks install prometheus
Installing http://rocks.tarantool.org/prometheus-scm-1.rockspec

Cloning into 'prometheus'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 19 (delta 2), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (19/19), 10.73 KiB | 10.73 MiB/s, done.
Resolving deltas: 100% (2/2), done.
prometheus scm-1 is now installed in /.rocks (license: BSD)

root@test2:/#

Re qala mme re khona ho fihlella li-module

root@test2:/# curl -D - -s http://127.0.0.1:8080/token
HTTP/1.1 200 Ok
Content-length: 44
Server: Tarantool http (tarantool v2.4.2-80-g18f2bc82d)
Connection: keep-alive

{"token":"e2tPq9l5Z3QZrewRf6uuoJUl3lJgSLOI"}

root@test2:/# curl -D - -s http://127.0.0.1:8080/token
HTTP/1.1 200 Ok
Content-length: 44
Server: Tarantool http (tarantool v2.4.2-80-g18f2bc82d)
Connection: keep-alive

{"token":"fR5aCA84gj9eZI3gJcV0LEDl9XZAG2Iu"}

root@test2:/# curl -D - -s http://127.0.0.1:8080/count
HTTP/1.1 200 Ok
Content-length: 11
Server: Tarantool http (tarantool v2.4.2-80-g18f2bc82d)
Connection: keep-alive

{"count":2}root@test2:/#

/ count e re fa boemo ba 200.
/token e fana ka lets'oao ebe o ngola letšoao lena ho database.

Lebelo la teko

Ha re sebetseng palo ea likopo tse 50. Likopo tsa tlholisano li tla ba 000.

root@test2:/# ab -c 500 -n 50000 http://127.0.0.1:8080/token
This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        Tarantool
Server Hostname:        127.0.0.1
Server Port:            8080

Document Path:          /token
Document Length:        44 bytes

Concurrency Level:      500
Time taken for tests:   14.578 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      7950000 bytes
HTML transferred:       2200000 bytes
Requests per second:    3429.87 [#/sec] (mean)
Time per request:       145.778 [ms] (mean)
Time per request:       0.292 [ms] (mean, across all concurrent requests)
Transfer rate:          532.57 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10 103.2      0    3048
Processing:    12   69 685.1     15   13538
Waiting:       12   69 685.1     15   13538
Total:         12   78 768.2     15   14573

Percentage of the requests served within a certain time (ms)
  50%     15
  66%     15
  75%     16
  80%     16
  90%     16
  95%     16
  98%     21
  99%     42
 100%  14573 (longest request)
root@test2:/#

Li-tokens li fanoa. 'Me re lula re rekota data. 99% ea likopo li phethiloe ka 42 milliseconds. Ka hona, re na le likopo tse ka bang 3500 motsotsoana mochining o monyane, moo ho nang le li-cores tse 2 le li-gigabytes tse 4 tsa mohopolo.

U ka boela ua khetha ba bang ba 50000 token le bona boleng ba eona.

U ka sebelisa eseng feela http, tsamaisa mesebetsi ea morao-rao e sebetsanang le data ea hau. Ho feta moo, ho na le li-trigger tse fapaneng. Ka mohlala, o ka letsetsa mesebetsi ho liapdeite, hlahloba ntho e itseng - lokisa likhohlano.

U ka ngola lits'ebetso tsa script ka kotloloho ho seva sa database ka boeona, 'me u se ke ua lekanyetsoa ke eng kapa eng, hokela li-module leha e le life ebe u kenya tšebetsong mohopolo ofe kapa ofe.

Seva ea kopo e ka fihlella li-server tsa kantle, ho bokella data le ho e kenya ho database ea eona. Lintlha tse tsoang polokelong ena li tla sebelisoa ke lits'ebetso tse ling.

Sena se tla etsoa ke Tarantula ka boeona, 'me ha ho hlokahale ho ngola kopo e fapaneng.

Qetellong

Ena ke karolo ea pele feela ea mosebetsi o moholo. Ea bobeli e tla hatisoa haufinyane ho blog ea Mail.ru Group, 'me ka sebele re tla eketsa sehokelo ho eona boitsebisong bona.

Haeba u thahasella ho ea liketsahalong tseo re etsang lintho tsena inthaneteng le ho botsa lipotso ka nako ea nnete, hokela ho DevOps ka mocha oa REBRAIN.

Haeba u hloka ho fallela lerung kapa u na le lipotso mabapi le lisebelisoa tsa hau, Ikutloe u lokolohile ho fana ka kopo.

PS Re na le litlhahlobo tse 2 tsa mahala ka khoeli, mohlomong projeke ea hau e tla ba e 'ngoe ea tsona.

Source: www.habr.com

Eketsa ka tlhaloso