Hauv Tarantool, koj tuaj yeem muab cov ntaub ntawv nrawm nrawm thiab daim ntawv thov ua haujlwm nrog lawv. Ntawm no yog yuav ua li cas yooj yim

Tsib xyoos dhau los kuv tau sim ua haujlwm nrog Tarantool, tab sis tom qab ntawd nws tsis ua haujlwm rau kuv. Tab sis tsis ntev los no kuv tau tuav lub vev xaib uas kuv tau tham txog Hadoop thiab MapReduce ua haujlwm li cas. Nyob ntawd lawv nug kuv ib lo lus nug: "Vim li cas ho tsis siv Tarantool rau txoj haujlwm no?"

Tawm ntawm kev xav paub, kuv txiav txim siab rov qab mus rau nws, sim qhov tseeb version - thiab lub sijhawm no kuv nyiam qhov project. Tam sim no kuv yuav qhia koj yuav ua li cas sau ib daim ntawv thov yooj yim hauv Tarantool, thauj khoom thiab xyuas nws cov kev ua tau zoo, thiab koj yuav pom tias txhua yam yooj yim thiab txias npaum li cas.

Hauv Tarantool, koj tuaj yeem muab cov ntaub ntawv nrawm nrawm thiab daim ntawv thov ua haujlwm nrog lawv. Ntawm no yog yuav ua li cas yooj yim

Dab tsi yog Tarantool

Tarantool tso nws tus kheej ua cov ntaub ntawv ceev ceev. Koj tuaj yeem muab cov ntaub ntawv koj xav tau rau ntawd. Ntxiv rau, rov ua dua lawv, shard - uas yog, faib ntau cov ntaub ntawv hla ntau lub servers thiab sib txuas cov txiaj ntsig los ntawm lawv - ua txhaum kev sib txuas ntawm tus tswv-tus tswv.

Qhov thib ob, qhov no yog daim ntawv thov server. Koj tuaj yeem sau koj daim ntawv thov rau ntawm nws, ua haujlwm nrog cov ntaub ntawv, piv txwv li, tshem tawm cov ntaub ntawv qub hauv keeb kwm yav dhau raws li qee txoj cai. Koj tuaj yeem sau tus neeg rau zaub mov Http ncaj qha hauv Tarantula uas yuav ua haujlwm nrog cov ntaub ntawv: muab lawv cov khoom kom muaj nuj nqis, sau cov ntaub ntawv tshiab muaj thiab txo nws tag nrho rau tus tswv.

Kuv nyeem ib tsab xov xwm hais txog yuav ua li cas cov txiv neej ua cov kab lus ntawm 300 kab, uas tsuas yog tawg thiab rushing - lawv muaj qhov tsawg kawg nkaus ntawm 20 cov lus ib ob. Ntawm no koj tuaj yeem tig ib ncig thiab sau daim ntawv thov loj heev, thiab nws yuav tsis khaws cia, xws li hauv PostgreS.

Kuv yuav sim piav qhia qee yam zoo li lub server no, tsuas yog yooj yim, hauv kab lus no.

chaw

Для теста я завел три стандартные виртуальные машины – жесткий диск на 20 гигабайт, Ubuntu 18.04. 2 виртуал CPU и 4 гига памяти.

Peb nruab Tarantool - khiav cov ntawv bash lossis ntxiv cov chaw cia khoom thiab ua kom tau txais kev txhim kho Tarantool. Txuas rau tsab ntawv - (curl -L https://tarantool.io/installer.sh | VER = 2.4 sudo -E bash). Peb muaj commands xws li:

tarantoolctl ua - cov lus txib tseem ceeb rau kev tswj cov xwm txheej Tarantula.
/etc/tarantool - Ntawm no yog tag nrho configuration.
var/log/tarantool - ntawm no yog cov cav.
var/lib/tarantool - cov ntaub ntawv nyob ntawm no, thiab tom qab ntawd nws muab faib ua piv txwv.

Muaj cov folders piv txwv-muaj thiab piv txwv-enable - nws muaj dab tsi yuav raug tso tawm - piv txwv cov ntaub ntawv teeb tsa nrog lua code, uas piav qhia txog qhov chaw nres nkoj nws mloog, lub cim xeeb dab tsi muaj rau nws, Vinyl lub cav teeb tsa, code uas khiav thaum pib. servers, sharding, queues, tshem tawm cov ntaub ntawv tsis siv, thiab lwm yam.

Cov xwm txheej ua haujlwm zoo li hauv PostgreS. Piv txwv li, koj xav khiav ob peb daim ntawv luam ntawm cov ntaub ntawv uas dai ntawm cov chaw nres nkoj sib txawv. Nws hloov tawm hais tias ob peb qhov piv txwv database tau pib ntawm ib tus neeg rau zaub mov, uas dai ntawm cov chaw nres nkoj sib txawv. Tej zaum lawv yuav muaj qhov sib txawv kiag li - ib qho piv txwv siv ib lub logic, qhov thib ob - lwm qhov.

Instance Management

Peb muaj cov lus txib tarantoolctl, uas tso cai rau koj los tswj cov xwm txheej Tarantula. Piv txwv li, tarantoolctl kos piv txwv yuav tshawb xyuas cov ntaub ntawv teeb tsa thiab hais tias - cov ntaub ntawv zoo yog tias tsis muaj syntax yuam kev nyob ntawd.

Koj tuaj yeem pom cov xwm txheej ntawm qhov piv txwv - tarantoolctl xwm txheej piv txwv. Ib yam li koj tuaj yeem pib, nres, rov pib dua.

Thaum piv txwv ua haujlwm, koj tuaj yeem txuas rau nws hauv ob txoj hauv kev.

1. Kev tswj xyuas console

Los ntawm lub neej ntawd, Tarantool qhib lub qhov (socket), cov ntawv ASCII ib txwm raug xa mus rau qhov ntawd los tswj Tarantool. Kev sib txuas rau lub console ib txwm tshwm sim nyob rau hauv tus neeg siv admin, tsis muaj kev lees paub, yog li tsis tas yuav txav lub console chaw nres nkoj sab nraud los tswj Tarantula.

Txhawm rau txuas siv hom no, koj yuav tsum sau Tarantoolctl sau npe piv txwv. Cov lus txib yuav qhib lub console thiab txuas raws li tus neeg siv admin. Tsis txhob nthuav tawm lub console chaw nres nkoj rau sab nraud - nws yog qhov zoo dua kom tso nws ua lub qhov (socket). Tom qab ntawd tsuas yog cov neeg uas muaj kev nkag mus sau rau hauv lub qhov (socket) yuav tuaj yeem txuas rau Tarantula.

Txoj kev no yog xav tau rau kev tswj hwm. Txhawm rau ua haujlwm nrog cov ntaub ntawv, siv txoj kev thib ob - binary raws tu qauv.

2. Siv binary raws tu qauv txuas mus rau ib qho chaw nres nkoj tshwj xeeb

Cov kev teeb tsa muaj cov lus qhia mloog, uas qhib qhov chaw nres nkoj rau kev sib txuas lus sab nraud. Qhov chaw nres nkoj no yog siv nrog binary raws tu qauv thiab authentication yog enabled muaj.

Rau qhov kev sib txuas no, tarantoolctl txuas mus rau tus lej chaw nres nkoj yog siv. Siv nws, koj tuaj yeem txuas mus rau tej thaj chaw deb servers, siv authentication thiab muab ntau txoj cai nkag.

Cov Ntaub Ntawv Cov Ntaub Ntawv thiab Box Module

Txij li Tarantool yog ob qho tib si database thiab daim ntawv thov server, nws muaj ntau yam modules. Peb txaus siab rau lub thawv module - nws siv ua haujlwm nrog cov ntaub ntawv. Thaum koj sau ib yam dab tsi rau lub thawv, Tarantool sau cov ntaub ntawv rau disk, khaws cia hauv nco, lossis ua lwm yam nrog nws.

Ntaub Ntawv

Piv txwv li, peb mus rau hauv lub thawv module thiab hu rau lub box.once muaj nuj nqi. Qhov no yuav yuam Tarantool khiav peb cov lej thaum lub server pib. Peb tsim ib qho chaw uas peb cov ntaub ntawv yuav muab khaws cia.

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

Tom qab ntawd, peb tsim ib qho kev ntsuas tseem ceeb - thawj - uas peb tuaj yeem tshawb nrhiav cov ntaub ntawv. Los ntawm lub neej ntawd, yog tias koj tsis qhia meej ib qho kev txwv, thawj daim teb hauv txhua cov ntaub ntawv yuav raug siv rau thawj qhov ntsuas.

Tom qab ntawd peb muab nyiaj pub dawb rau tus neeg siv qhua, hauv qab uas peb txuas ntawm binary raws tu qauv. Peb tso cai nyeem, sau ntawv thiab ua tiav thoob plaws txhua qhov piv txwv.

Piv rau cov ntaub ntawv qub, txhua yam ntawm no yog qhov yooj yim heev. Peb muaj qhov chaw - thaj chaw uas peb cov ntaub ntawv tsuas yog khaws cia. Txhua daim ntawv yog hu ua tuple. Nws tau ntim rau hauv MessagePack. Qhov no yog hom ntawv txias heev - nws yog binary thiab siv qhov chaw tsawg dua - 18 bytes piv rau 27.

Hauv Tarantool, koj tuaj yeem muab cov ntaub ntawv nrawm nrawm thiab daim ntawv thov ua haujlwm nrog lawv. Ntawm no yog yuav ua li cas yooj yim

Nws yog qhov yooj yim heev los ua haujlwm nrog nws. Yuav luag txhua kab, txhua cov ntaub ntawv khaws tseg tuaj yeem muaj kab sib txawv kiag li.

Peb tuaj yeem saib txhua qhov chaw siv Box.space hais kom ua. Txhawm rau xaiv ib qho piv txwv, sau box.space piv txwv thiab tau txais cov ntaub ntawv tiav txog nws.

Tarantool muaj ob lub cav built-in: Nco thiab Vinyl. Memory khaws tag nrho cov ntaub ntawv hauv nco. Yog li ntawd, txhua yam ua haujlwm yooj yim thiab nrawm. Cov ntaub ntawv tau muab pov tseg rau hauv disk, thiab tseem muaj cov txheej txheem sau ua ntej, yog li peb yuav tsis poob dab tsi yog tias lub server poob.

Vinyl khaws cov ntaub ntawv ntawm disk hauv ib daim ntawv uas peb paub ntau dua - uas yog, koj tuaj yeem khaws cov ntaub ntawv ntau dua li peb nco, thiab Tarantula yuav nyeem nws ntawm disk.

Tam sim no peb yuav siv Memory.

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>

Qhov ntsuas:

Thawj qhov ntsuas yuav tsum tau tsim rau txhua qhov chaw, vim tias tsis muaj nws tsis muaj dab tsi yuav ua haujlwm. Raws li nyob rau hauv tej database, peb tsim thawj daim teb - ntaub ntawv ID.

Qhov:

Ntawm no peb qhia seb peb qhov Performance index muaj li cas. Nws muaj ib feem - thawj daim teb peb yuav siv yog hom unsigned - ib tug zoo integer. Raws li kuv nco qab los ntawm cov ntaub ntawv, tus lej siab tshaj plaws uas tuaj yeem yog 18 quintillion. Qhov ntawd yog ntau.

Tom qab ntawd peb tuaj yeem ntxig cov ntaub ntawv siv cov lus txib ntxig.

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>

Thawj daim teb yog siv los ua tus yuam sij tseem ceeb, yog li nws yuav tsum yog qhov tshwj xeeb. Peb tsis txwv los ntawm tus naj npawb ntawm kab, yog li peb tuaj yeem ntxig cov ntaub ntawv ntau npaum li peb xav tau. Lawv tau teev nyob rau hauv MessagePack hom, uas kuv tau piav saum toj no.

Cov ntaub ntawv tawm

Tom qab ntawd peb tuaj yeem tso saib cov ntaub ntawv siv cov lus txib xaiv.

Box.example.select nrog tus yuam sij {1} yuav tso saib qhov xav tau nkag. Yog tias peb txo tus yuam sij, peb yuav pom tag nrho cov ntaub ntawv uas peb muaj. Lawv txhua tus sib txawv ntawm tus naj npawb ntawm kab, tab sis ntawm no, hauv paus ntsiab lus, tsis muaj lub tswv yim ntawm kab - muaj cov lej.

Yuav muaj cov ntaub ntawv ntau npaum li cas. Thiab piv txwv li, peb yuav tsum tshawb nrhiav lawv los ntawm daim teb thib ob. Txhawm rau ua qhov no, peb tsim qhov ntsuas thib ob tshiab.


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

Peb siv Create_index hais kom ua.
Wb hu ua Secondary.

Tom qab qhov no koj yuav tsum tau qhia cov parameter. Hom Index yog TREE. Tej zaum nws yuav tsis tshwj xeeb, yog li nkag Unique = cuav.

Tom qab ntawd peb qhia seb qhov twg peb qhov Performance index muaj. Field yog tus naj npawb ntawm daim teb uas peb khi qhov ntsuas, thiab qhia cov hlua hom. Thiab yog li ntawd nws tau tsim.

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>

Tam sim no qhov no yog qhov peb tuaj yeem hu nws:

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

Preservation

Yog tias peb rov pib dua qhov piv txwv thiab sim hu rau cov ntaub ntawv dua, peb yuav pom tias nws tsis nyob ntawd - txhua yam yog khoob. Qhov no tshwm sim vim tias Tarantool ua cov chaw kuaj xyuas thiab khaws cov ntaub ntawv rau disk, tab sis yog tias peb tsis ua haujlwm kom txog thaum lub sijhawm txuag tom ntej, peb yuav poob tag nrho cov haujlwm - vim tias peb yuav rov qab los ntawm qhov chaw kuaj xyuas kawg, uas yog, piv txwv li, ob teev dhau los.

Nws yuav tsis ua hauj lwm kom txuag txhua ob, vim hais tias tas li pov tseg 20 GB rau disk tsis yog ib lub tswv yim zoo.

Rau lub hom phiaj no, lub tswv yim ntawm kev sau-ua ntej log tau tsim thiab siv. Nrog nws cov kev pab, rau txhua qhov kev hloov pauv hauv cov ntaub ntawv, kev nkag yog tsim nyob rau hauv cov ntaub ntawv sau ua ntej me me.

Txhua qhov nkag mus rau qhov chaw kuaj xyuas yog khaws cia rau hauv lawv. Rau cov ntaub ntawv no peb teeb qhov loj me - piv txwv li, 64 MB. Thaum nws puv, cov ntaubntawv povthawj siv pib mus rau cov ntaub ntawv thib ob. Thiab tom qab rov pib dua, Tarantool rov qab los ntawm qhov chaw kuaj xyuas kawg thiab tom qab ntawd dov tag nrho cov kev hloov pauv tom qab kom txog thaum nws nres.

Hauv Tarantool, koj tuaj yeem muab cov ntaub ntawv nrawm nrawm thiab daim ntawv thov ua haujlwm nrog lawv. Ntawm no yog yuav ua li cas yooj yim

Txhawm rau ua tiav cov ntaub ntawv kaw tseg, koj yuav tsum qhia qhov kev xaiv hauv box.cfg chaw (hauv cov ntaub ntawv example.lua):

wal_mode = “write”;

kev siv cov ntaub ntawv

Nrog dab tsi peb tau sau tam sim no, koj tuaj yeem siv Tarantula los khaws cov ntaub ntawv thiab nws yuav ua haujlwm sai heev li cov ntaub ntawv. Thiab tam sim no lub icing ntawm lub ncuav mog qab zib yog qhov koj tuaj yeem ua nrog txhua yam.

Sau daim ntawv thov

Piv txwv li, cia peb sau daim ntawv thov hauv qab no rau Tarantula

Saib daim ntawv thov hauv qab tus 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()

Peb tshaj tawm qee lub rooj hauv lua uas txhais cov cim. Lub phaj no yog xav tau los tsim ib txoj hlua random.

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

После этого мы объявляем функцию – randomString и придадим в скобках значение длины.

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

Tom qab ntawd peb txuas lub http router thiab http server rau peb Tarantula server, JSON, uas peb yuav xa mus rau tus neeg siv khoom.

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

Tom qab no, peb pib ntawm qhov chaw nres nkoj 8080 ntawm tag nrho http server interfaces, uas yuav teev txhua qhov kev thov thiab qhov tsis raug.

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

Tom ntej no, peb tshaj tawm txoj hauv kev, yog li yog tias qhov kev thov nrog GET txoj kev tuaj txog ntawm qhov chaw nres nkoj 8080 / suav, ces peb hu rau txoj haujlwm los ntawm ib kab. Nws rov qab cov xwm txheej - 200, 404, 403 lossis lwm yam uas peb tau hais tseg.

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

Nyob rau hauv lub cev peb rov qab json.encode, nyob rau hauv nws peb qhia suav thiab getcount, uas yog hu ua thiab qhia cov naj npawb ntawm cov ntaub ntawv nyob rau hauv peb database.

Ob txoj kev

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)

Qhov twg hauv kab router:route({method = 'GET', path = '/token'}, function() peb hu rau qhov muaj nuj nqi thiab tsim ib tug token.

Txoj hlua local token = randomString(32) yog ib txoj hlua random ntawm 32 cim.
Hauv kab local last = box.space.example:len() peb tshem tawm cov ntsiab lus kawg.
Thiab nyob rau hauv kab box.space.example:insert{ last + 1, token } peb sau cov ntaub ntawv rau hauv peb lub database, uas yog, peb tsuas nce tus ID los ntawm 1. Qhov no yuav ua tau, los ntawm txoj kev, tsis tsuas yog nyob rau hauv no clumsy txoj kev. Muaj ib ntus rau qhov no hauv Tarantula.

Peb sau lub cim rau ntawd.

Yog li, peb tau sau daim ntawv thov hauv ib daim ntawv. Koj tuaj yeem tswj xyuas cov ntaub ntawv ncaj qha rau ntawd, thiab lub thawv module yuav ua txhua yam haujlwm qias neeg rau koj.

Nws mloog http thiab ua haujlwm nrog cov ntaub ntawv, txhua yam nyob hauv ib qho piv txwv - ob qho tib si hauv daim ntawv thov thiab cov ntaub ntawv. Yog li ntawd, txhua yam tshwm sim sai heev.

Txhawm rau pib peb nruab http module:

Yuav ua li cas peb ua li no, saib nyob rau hauv lub spoiler

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:/#

Peb kuj xav tau prometheus khiav:

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:/#

Peb tso tawm thiab tuaj yeem nkag mus rau cov modules

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:/#

/ suav muab peb cov xwm txheej 200.
/token teeb meem lub token thiab sau qhov token no rau hauv database.

Kev ntsuas ceev

Cia peb ua tus qauv ntsuas rau 50 qhov kev thov. Yuav muaj 000 qhov kev thov sib tw.

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:/#

Token raug muab tso tawm. Thiab peb niaj hnub sau cov ntaub ntawv. 99% ntawm kev thov tau ua tiav hauv 42 milliseconds. Raws li, peb muaj txog 3500 thov ib ob ntawm lub tshuab me me nrog 2 cores thiab 4 gigabytes ntawm lub cim xeeb.

Koj tuaj yeem xaiv qee qhov 50000 token thiab pom nws tus nqi.

Koj tuaj yeem siv tsis yog http nkaus xwb, tab sis kuj tseem khiav haujlwm tom qab uas ua rau koj cov ntaub ntawv. Ntxiv rau muaj ntau yam ua rau. Piv txwv li, koj tuaj yeem hu xov tooj rau kev hloov kho tshiab, tshawb xyuas ib yam dab tsi - yog qhov tsis sib haum xeeb.

Koj tuaj yeem sau cov ntawv thov ncaj qha rau hauv database server nws tus kheej, thiab tsis txwv los ntawm ib yam dab tsi, txuas ib qho modules thiab siv cov logic.

Daim ntawv thov server tuaj yeem nkag mus rau lwm cov servers, khaws cov ntaub ntawv thiab ntxiv rau nws cov ntaub ntawv. Cov ntaub ntawv los ntawm cov ntaub ntawv no yuav raug siv los ntawm lwm cov ntawv thov.

Tarantula yuav ua qhov no nws tus kheej, thiab koj yuav tsis tas yuav sau ib daim ntawv thov cais.

Nyob rau hauv xaus

Qhov no tsuas yog thawj feem ntawm txoj haujlwm loj. Qhov thib ob yuav tsum tau tshaj tawm sai sai ntawm Mail.ru Group blog, thiab peb yuav twv yuav raug hu ntxiv qhov txuas rau nws hauv cov ntaub ntawv no.

Yog tias koj txaus siab koom nrog cov xwm txheej uas peb tsim cov khoom no hauv online thiab nug cov lus nug hauv lub sijhawm, qhib rau DevOps los ntawm REBRAIN channel.

Yog tias koj xav tau txav mus rau huab lossis muaj lus nug txog koj qhov kev tsim kho vaj tse, Xav tias dawb xa daim ntawv thov.

PS Peb muaj 2 kev tshuaj xyuas dawb hauv ib hlis, tej zaum koj qhov project yuav yog ib qho ntawm lawv.

Tau qhov twg los: www.hab.com

Ntxiv ib saib