I roto i te Tarantool, ka taea e koe te whakakotahi i te papaaarangi tino tere me tetahi tono hei mahi tahi me ratou. Anei te ngawari o te mahi

E rima tau ki muri ka whakamatau ahau ki te mahi tahi me Tarantool, engari kaore i pai ki ahau. Engari no tata nei ka whakahaere ahau i tetahi paetukutuku i korero ahau mo Hadoop me te mahi a MapReduce. I reira ka patai mai ratou ki ahau: "He aha te kore e whakamahi i a Tarantool mo tenei mahi?"

I runga i te hiahia, ka whakatau ahau ki te hoki ki reira, whakamatau i te putanga hou - a i tenei wa i tino pai ahau ki te kaupapa. Inaianei ka whakaatu ahau ki a koe me pehea te tuhi i tetahi tono ngawari ki Tarantool, utaina me te tirotiro i ana mahi, ka kite koe i te ngawari me te hauhautanga o nga mea katoa.

I roto i te Tarantool, ka taea e koe te whakakotahi i te papaaarangi tino tere me tetahi tono hei mahi tahi me ratou. Anei te ngawari o te mahi

He aha te Tarantool

Ka noho a Tarantool hei putunga korero tere-tere. Ka taea e koe te whakauru i nga raraunga e hiahia ana koe ki reira. Hei taapiri atu, whakahiatohia, he kowhatu - ara, wehea te nui o nga raraunga puta noa i te maha o nga kaitoro me te whakakotahi i nga hua mai i a raatau - hanga i nga hononga rangatira-a-ariki-whakaaro.

Tuarua, he tūmau tono tenei. Ka taea e koe te tuhi i o tono ki runga, mahi me nga raraunga, hei tauira, muku i nga rekoata tawhito i te papamuri kia rite ki etahi ture. Ka taea e koe te tuhi tika i tetahi tūmau Http ki Tarantula ka mahi me nga raraunga: hoatu te rahinga, tuhia nga raraunga hou ki reira ka whakaheke katoa ki te rangatira.

I panui au i tetahi tuhinga mo te mahi a nga taane i te rarangi karere 300 rarangi, e pakaru noa ana, e tere ana - he iti rawa te mahi o te 20 karere mo ia hekona. I konei ka taea e koe te huri me te tuhi i tetahi tono nui rawa atu, kaore e waiho hei rokiroki, penei i te PostgreS.

Ka ngana ahau ki te whakaahua i tetahi mea penei i tenei tūmau, he maamaa noa, i roto i tenei tuhinga.

tāutanga

Mo te whakamatautau, i timata ahau e toru nga miihini mariko paerewa - he puku pakeke 20 GB, Ubuntu 18.04. 2 PTM mariko me te 4 gigs o te mahara.

Ka whakauruhia e matou a Tarantool - whakahaere i te tuhinga bash me te taapiri i tetahi putunga ka pai ki te whakauru i a Tarantool. Hononga ki te tuhinga - (curl -L https://tarantool.io/installer.sh | VER=2.4 sudo -E bash). Kei a matou nga whakahau penei:

taratoolctl — te whakahau matua mo te whakahaere i nga tauira Tarantula.
/etc/tarantool - koinei te whirihoranga katoa.
var/log/tarantool - anei nga rakau.
var/lib/tarantool — kei konei nga raraunga, katahi ka wehea hei tauira.

He kōpaki tauira-e waatea ana me te tauira-whakahohe - kei roto nga mea ka whakarewahia - he konae whirihoranga tauira me te waehere lua, e whakaatu ana he aha nga tauranga e whakarongo ana, he aha te mahara e waatea ana ki a ia, nga tautuhinga miihini Vinyl, waehere ka rere i te tiimatanga. tūmau, sharding, tūtira, mukunga o nga raraunga tawhito, aha atu.

Ka mahi nga tauira penei i te PostgreS. Hei tauira, e hiahia ana koe ki te whakahaere i etahi kape o te putunga raraunga e iri ana ki runga i nga tauranga rereke. Ko te ahua he maha nga waahi raraunga ka whakarewahia i runga i te tūmau kotahi, e iri ana ki runga i nga tauranga rereke. He rereke pea o raatau tautuhinga - ko tetahi tauira ka whakatinana i tetahi arorau, ko te tuarua - tetahi atu.

Te whakahaere tauira

Kei a matou te whakahau tarantoolctl, ka taea e koe te whakahaere i nga tauira Tarantula. Hei tauira, ka tirohia e te tauira tirotiro tarantoolctl te konae whirihoranga me te kii - kei te pai te konae mena karekau he hapa wetereo kei reira.

Ka taea e koe te kite i te mana o te tauira - tarantoolctl status example. I te ara ano ka taea e koe te timata, mutu, whakaara ano.

I te wa e rere ana te tauira, ka taea e koe te hono atu ki a ia ma nga huarahi e rua.

1. Papatohu whakahaere

Ma te taunoa, ka whakatuwherahia e Tarantool tetahi turanga, ka tukuna nga tuhinga ASCII ki reira hei whakahaere i a Tarantool. Ko te hononga ki te papatohu ka puta tonu i raro i te kaiwhakamahi kaiwhakahaere, kaore he motuhēhēnga, na reira kaore he take ki te whakaputa i te tauranga papatohu hei whakahaere i a Tarantula.

Hei hono ma te whakamahi i tenei tikanga, me whakauru koe ki te Tarantoolctl whakauru ingoa tauira. Ka whakarewahia e te whakahau te papatohu me te hono hei kaiwhakamahi kaiwhakahaere. Kaua rawa e tukuna te tauranga papatohu ki waho - he pai ake te waiho hei turanga wae. Na ko te hunga e whai waahi ana ki te tuhi ki te turanga ka taea te hono atu ki a Tarantula.

Ko tenei tikanga e hiahiatia ana mo nga mea whakahaere. Hei mahi me nga raraunga, whakamahia te tikanga tuarua - te kawa rua.

2. Te whakamahi i te kawa rua hei hono atu ki tetahi tauranga motuhake

Kei roto i te whirihoranga he tohutohu whakarongo, e whakatuwhera ana i te tauranga mo nga korero o waho. Ka whakamahia tenei tauranga me te kawa rua me te motuhēhēnga kei reira.

Mo tenei hononga, ka whakamahia te tarantoolctl hono ki te tau tauranga. Ma te whakamahi, ka taea e koe te hono atu ki nga kaitoro mamao, te whakamahi motuhēhēnga me te tuku momo mana uru.

Te Raraunga Raraunga me te Pouaka Pouaka

I te mea ko Tarantool he papaaarangi me te tūmau tono, he maha nga waahanga. Kei te pirangi matou ki te waahanga pouaka - ka whakamahia te mahi me nga raraunga. Ka tuhi koe i tetahi mea ki te pouaka, ka tuhia e Tarantool nga raraunga ki te kopae, ka penapena ki roto i te mahara, ka mahi ranei i tetahi atu mea.

Tuhia

Hei tauira, ka haere matou ki roto i te waahanga pouaka ka karangahia te mahi box.once. Ma tenei ka kaha a Tarantool ki te whakahaere i ta maatau waehere i te wa i timata ai te tūmau. Ka hangaia e matou he waahi ka penapenahia o maatau raraunga.

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

I muri i tenei, ka hangaia e matou he tohu tuatahi - tuatahi - e taea ai e matou te rapu raraunga. Ma te taunoa, ki te kore koe e tohu i etahi tawhā, ka whakamahia te mara tuatahi o ia rekoata mo te taupū tuatahi.

Katahi ka tukuna he karaati ki te manuhiri manuhiri, ka hono atu ma te kawa rua. Ka whakaaetia e matou te panui, te tuhi me te mahi puta noa i te tauira katoa.

Ka whakatauritea ki nga papaa raraunga tikanga, he maamaa noa nga mea katoa i konei. He waahi kei a matou - he waahi kei te penapena noa o taatau raraunga. Ko ia rekoata ka kiia he tuple. Kei roto i te MessagePack. He ahua tino hauhautanga tenei - he takirua, he iti ake te mokowā - 18 paita ki te 27.

I roto i te Tarantool, ka taea e koe te whakakotahi i te papaaarangi tino tere me tetahi tono hei mahi tahi me ratou. Anei te ngawari o te mahi

He tino watea ki te mahi tahi me ia. Tata ki ia raina, ia rekoata raraunga ka rereke nga pou.

Ka taea e tatou te tiro i nga waahi katoa ma te whakamahi i te whakahau Box.space. Hei whiriwhiri i tetahi tauira motuhake, tuhia he tauira pouaka.mokowā ka whiwhi korero katoa mo taua mea.

E rua nga miihini hanga-i roto a Tarantool: Mahara me te Vinyl. Ka penapena nga raraunga katoa ki te mahara. Na reira, ka mahi ngawari nga mea katoa me te tere. Ka makahia nga raraunga ki te kopae, kei reira ano he tikanga tuhi ki mua, no reira ka kore e ngaro tetahi mea mena ka pakaru te tūmau.

Ko te Vinyl e rongoa ana i nga raraunga i runga i te kōpae i roto i te ahua mohio ake ki a maatau - ara, ka taea e koe te penapena raraunga nui atu i to maatau mahara, ka panuihia e Tarantula mai i te kōpae.

Mo tenei wa ka whakamahi tatou i te Mahara.

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>

Tohu:

Me hanga he taurangi tuatahi mo tetahi waahi, no te mea kaore he mea e mahi. Pērā i roto i tetahi pātengi raraunga, ka hangaia e matou te mara tuatahi - record ID.

Nga waahanga:

I konei ka tohuhia he aha ta tatou taurangi. Kotahi te wahanga - ko te mara tuatahi ka whakamahia e matou he momo kore haina - he tauoti totika. Ki taku mahara mai i nga tuhinga, ko te nui rawa o te tau ka taea ko te 18 quintillion. He nui tera.

Na ka taea e tatou te whakauru raraunga ma te whakamahi i te whakahau whakauru.

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>

Ka whakamahia te āpure tuatahi hei kī matua, nā reira me ahurei. Kaore matou i te whakaitihia e te maha o nga pou, na reira ka taea e matou te whakauru i nga raraunga e hiahia ana matou ki reira. Kua tohua i roto i te whakatakotoranga MessagePack, i korerohia e ahau i runga ake nei.

Putanga Raraunga

Na ka taea e matou te whakaatu i nga raraunga ma te whakamahi i te whakahau whiriwhiri.

Box.example.select me te kī {1} ka whakaatu i te urunga e hiahiatia ana. Mena ka whakahekehia te ki, ka kite tatou i nga rekoata katoa kei a tatou. He rereke katoa i te maha o nga pou, engari i konei, ko te tikanga, kaore he kaupapa o nga pou - he tau mara.

Ka taea te nui o nga raraunga. A hei tauira, me rapu tatou ma te mara tuarua. Ki te mahi i tenei, ka hangaia e matou he taurangi tuarua hou.


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

Ka whakamahia e matou te whakahau Create_index.
Karangahia ko te Tuarua.

I muri i tenei ka hiahia koe ki te tautuhi i nga tawhā. Ko te momo tohu he TREE. Ehara pea i te mea ahurei, no reira ka tomo Unique = teka.

Katahi ka tohuhia he aha nga waahanga o to maatau taurangi. Ko te āpure te tau o te āpure ka herea e mātou te taupū, ka whakapūtā te momo aho. Na reira i hanga ai.

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>

Inaianei me penei ta tatou karanga:

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

Te tiaki

Mena ka timata ano tatou i te tauira ka ngana ki te waea ano i nga raraunga, ka kite tatou kaore i reira - he kau nga mea katoa. Ka puta tenei na te mea ka mahi a Tarantool i nga waahi tirotiro me te penapena i nga raraunga ki te kopae, engari ki te mutu taatau mahi kia tae ra ano ki te penapena e whai ake nei, ka ngaro nga mahi katoa - na te mea ka ora mai i te waahi tirotiro whakamutunga, penei, hei tauira, e rua haora ki muri.

E kore e pai ki te penapena ia hekona, na te mea ko te tuku tonu i te 20 GB ki runga kōpae ehara i te mea pai.

Mo tenei kaupapa, i hangahia, i whakatinanahia te ariā o te tuhi-a-mua. Ma tana awhina, mo nga huringa katoa o nga raraunga, ka hangaia he urunga ki roto i te konae rangitaki tuhi-i mua.

Ko ia urunga tae atu ki te waahi tirotiro ka rongoa ki roto. Mo enei kōnae ka tautuhia te rahi - hei tauira, 64 MB. Ka ki tonu, ka timata te tuhi ki te haere ki te konae tuarua. A, i muri i te tiimatanga, ka whakahokia mai a Tarantool mai i te waahi tirotiro whakamutunga ka huri i nga whakawhitinga katoa i muri mai kia mutu ra ano.

I roto i te Tarantool, ka taea e koe te whakakotahi i te papaaarangi tino tere me tetahi tono hei mahi tahi me ratou. Anei te ngawari o te mahi

Hei whakahaere i taua rekoata, me tohu koe i te whiringa ki nga tautuhinga box.cfg (i te konae tauira.lua):

wal_mode = “write”;

te whakamahi raraunga

Ma nga mea kua tuhia e matou inaianei, ka taea e koe te whakamahi i te Tarantula ki te penapena raraunga, ka tere te mahi hei putunga raraunga. Na inaianei ko te huka i runga i te keke ko te mea ka taea e koe ki te katoa.

Te tuhi tono

Hei tauira, me tuhi te tono e whai ake nei mo Tarantula

Tirohia te tono i raro i te kaipahua

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()

Ka whakapuakihia e matou etahi ripanga i roto i te lua e whakaatu ana i nga tohu. Ka hiahiatia tenei pereti hei whakaputa i te aho matapōkere.

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

Whai muri i tera, ka whakapuakihia e matou te mahi - randomString ka hoatu te uara roa i roto i nga reu.

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

Na ka honoa e matou te pouara http me te tūmau http ki ta matou tūmau Tarantula, JSON, ka tukuna atu e matou ki te kiritaki.

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

I muri i tenei, ka timata matou i runga i te tauranga 8080 i runga i nga atanga tūmau http katoa, ka tuhia nga tono me nga hapa katoa.

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

I muri mai, ka whakapuakihia e matou te huarahi, na mena ka tae mai tetahi tono me te tikanga GET ki te tauranga 8080 / tatau, ka karangahia te mahi mai i te raina kotahi. Ka whakahokia mai te mana - 200, 404, 403, etahi atu ranei ka tohua e matou.

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

I roto i te tinana ka hoki mai tatou i te json.encode, kei roto ka tohuhia te tatau me te whiwhi tatau, e kiia ana me te whakaatu i te maha o nga rekoata i roto i ta maatau papaarangi.

Tikanga tuarua

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)

Kei hea i te raina pouara:route({tikanga = 'GET', ara = '/tohu'}, mahi() ka karangahia e matou te mahi me te whakaputa tohu.

Raina tohu rohe = randomString(32) he aho matapōkere e 32 ngā pūāhua.
I roto i te raina rohe whakamutunga = box.space.example:len() tango tatou i te huānga whakamutunga.
Na i roto i te raina box.space.example:insert{ last + 1, tohu } ka tuhia e matou nga raraunga ki roto i to maatau paparangi, ara, ka whakanui noa i te ID ma te 1. Ka taea tenei, ma te ara, ehara i te mea noa i tenei ara poauau. He raupapa mo tenei i Tarantula.

Ka tuhia e matou te tohu ki reira.

Na, i tuhia e matou te tono ki te konae kotahi. Ka taea e koe te whakahaere tika i nga raraunga i reira, ka mahia e te pouaka pouaka nga mahi paru katoa mo koe.

Ka whakarongo ki te http ka mahi tahi me nga raraunga, he mea kotahi noa nga mea katoa - ko te tono me te raraunga. No reira, ka tere nga mea katoa.

Hei tiimata ka whakauruhia e matou te waahanga http:

Me pehea te mahi i tenei, tirohia i raro i te kaipahua

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

Me oma ano hoki tatou i te prometheus:

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

Ka whakarewahia e maatau ka uru atu ki nga waahanga

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

Ka homai e /count te mana 200.
Ka tukuna he tohu ka tuhia e te /token tenei tohu ki te papaunga raraunga.

Te whakamatautau i te tere

Me whakahaere he tohu mo te 50 tono. Ka 000 nga tono whakataetae.

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

Ka tukuna nga tohu. A kei te tuhi tonu matou i nga raraunga. 99% o nga tono i tukatukahia i roto i te 42 milliseconds. No reira, tata ki te 3500 nga tono mo ia hekona i runga i tetahi miihini iti me te 2 matua me te 4 gigabytes o te mahara.

Ka taea hoki e koe te kowhiri i etahi tohu 50000 ka kite i tona uara.

Ka taea e koe te whakamahi i te http anake, engari ka whakahaere hoki i nga mahi papamuri e tukatuka ana i o raraunga. I tua atu he maha nga momo keu. Hei tauira, ka taea e koe te karanga i nga mahi i runga i nga whakahoutanga, tirohia tetahi mea - nga pakanga tika.

Ka taea e koe te tuhi tika i nga tono tuhinga ki roto i te tuumau papaaarangi, kaua e whakawhäitihia e tetahi mea, hono atu i nga waahanga me te whakatinana i nga tikanga.

Ka taea e te tūmau tono te uru atu ki nga kaitoro o waho, te tiki raraunga me te taapiri atu ki tana putunga raraunga. Ko nga raraunga mai i tenei paataka raraunga ka whakamahia e etahi atu tono.

Ka mahia e Tarantula tenei, kaore koe e tuhi i tetahi tono motuhake.

I te mutunga

Koinei anake te wahanga tuatahi o te mahi nui. Ko te tuarua ka whakaputahia i runga i te blog Mail.ru Group, a ka tino taapirihia e matou he hononga ki tenei tuhinga.

Mena kei te pirangi koe ki te haere ki nga huihuinga ka hangaia e matou enei mea ki runga ipurangi me te patai i nga paatai ​​​​i roto i te waa, waea mai hongere DevOps na REBRAIN.

Mena ka hiahia koe ki te neke ki te kapua, he patai ranei mo to hanganga, kia pai ki te waiho he tono.

PS E 2 a matou arotake kore utu ia marama, tera pea ko to kaupapa tetahi o era.

Source: will.com

Tāpiri i te kōrero