Skip to content

Bench echo #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# Go output
*.out

# Node
node_modules
package-lock.json
package.json

# Tmp
*.tmp
tests/tnt/tmp
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif

test:
tt rocks install vshard 0.1.26
tt rocks install --force-lock metrics 1.0.0
$(GO_CMD) test ./... -race -parallel=10 -timeout=$(TEST_TIMEOUT) -covermode=atomic -coverprofile=coverage.out.tmp -coverpkg="./..."
@cat coverage.out.tmp | grep -v "mock" > coverage.out
@rm coverage.out.tmp
Expand Down
6 changes: 0 additions & 6 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ local vshard = require 'vshard'
local NAME = os.getenv("TEST_TNT_WORK_DIR")
local fiber = require('fiber')

-- Check if we are running under test-run
if os.getenv('ADMIN') then
test_run = require('test_run').new()
require('console').listen(os.getenv('ADMIN'))
end

-- Call a configuration provider
local cfg = {
sharding = {
Expand Down
9 changes: 9 additions & 0 deletions examples/bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
start:
docker-compose up -d --no-deps --build webserver

wrk:
go-wrk http://0.0.0.0:8080

k6:
K6_PROMETHEUS_RW_SERVER_URL=http://0.0.0.0:9090/api/v1/write \
k6 run -o experimental-prometheus-rw k6.js --vus 1000 --duration 60s
29 changes: 29 additions & 0 deletions examples/bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Bench

## Grafana
```
Login: admin
Password: secret
```


### Sequence
```mermaid
sequenceDiagram
participant K6
participant LuaProxy as Tarantool VShard Proxy
participant GoProxy as Go VShard As Proxy
participant Tarantool

K6->>LuaProxy: Stage 1 via msgpack
LuaProxy->>Tarantool: echo(a)
Tarantool-->>LuaProxy: a

Note right of K6: Check k6 metrics

K6->>GoProxy: Stage 2 via gRPC
GoProxy->>Tarantool: echo(a)
Tarantool-->>GoProxy: a

Note right of K6: Check k6 metrics
```
165 changes: 165 additions & 0 deletions examples/bench/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#!/usr/bin/env tarantool

require('strict').on()

local uuid = require('uuid')
local vshard = require 'vshard'
local yaml = require('yaml')
local fio = require('fio')
local errno = require('errno')

-- METRICS
local metrics = require('metrics')
local http_server = require('http.server')

-- Define helper functions
local http_metrics_handler = require('metrics.plugins.prometheus').collect_http


-- CONFIGURATION
function read_file(path)
local file = fio.open(path)
if file == nil then
return nil, string.format('Failed to open file %s: %s', path, errno.strerror())
end
local buf = {}
while true do
local val = file:read(1024)
if val == nil then
return nil, string.format('Failed to read from file %s: %s', path, errno.strerror())
elseif val == '' then
break
end
table.insert(buf, val)
end
file:close()
return table.concat(buf, '')
end



local function parse_yaml(data)
local sections = {'default'}

if app_name ~= nil then
table.insert(sections, app_name)

if instance_name ~= nil then
table.insert(sections, app_name .. '.' .. instance_name)
end
end

local ok, cfg = pcall(yaml.decode, data)
if not ok then
return nil, cfg
end

local res = {}

for _, section in ipairs(sections) do
for argname, argvalue in pairs(cfg[section] or {}) do
res[argname] = argvalue
end
end

return res
end

-- Get instance name
local fiber = require('fiber')
local NAME = os.getenv("TNT_NAME")
local CONFIG_FILE = os.getenv("CONFIG_FILE")



local d = yaml.decode(read_file(CONFIG_FILE))
local storages = d.storages

-- Call a configuration provider
local cfg = {
sharding = {
['cbf06940-0790-498b-948d-042b62cf3d29'] = { -- replicaset #1
replicas = {
['8a274925-a26d-47fc-9e1b-af88ce939412'] = {
uri = 'storage:storage@' .. storages["storage_1_a"],
name = 'storage_1_a',
master = true,
},
['3de2e3e1-9ebe-4d0d-abb1-26d301b84633'] = {
uri = 'storage:storage@' .. storages["storage_1_b"],
name = 'storage_1_b'
},
},
}, -- replicaset #1
['ac522f65-aa94-4134-9f64-51ee384f1a54'] = { -- replicaset #2
replicas = {
['1e02ae8a-afc0-4e91-ba34-843a356b8ed7'] = {
uri = 'storage:storage@' .. storages["storage_2_a"],
name = 'storage_2_a',
master = true,
},
['001688c3-66f8-4a31-8e19-036c17d489c2'] = {
uri = 'storage:storage@' .. storages["storage_2_b"],
name = 'storage_2_b'
}
},
}, -- replicaset #2
}, -- sharding
replication_connect_quorum = 0, -- its oke if we havent some replicas
}


-- Name to uuid map
local names = {
['storage_1_a'] = '8a274925-a26d-47fc-9e1b-af88ce939412',
['storage_1_b'] = '3de2e3e1-9ebe-4d0d-abb1-26d301b84633',
['storage_1_c'] = '3de2e3e1-9ebe-4d0d-abb1-26d301b84635',
['storage_2_a'] = '1e02ae8a-afc0-4e91-ba34-843a356b8ed7',
['storage_2_b'] = '001688c3-66f8-4a31-8e19-036c17d489c2',
}

replicasets = {'cbf06940-0790-498b-948d-042b62cf3d29',
'ac522f65-aa94-4134-9f64-51ee384f1a54'}



rawset(_G, 'vshard', vshard) -- set as global variable

-- Если мы являемся роутером, то применяем другой конфиг
if NAME == "router" then
cfg.listen = "0.0.0.0:12000"
cfg['bucket_count'] = 100
local router = vshard.router.new('router', cfg)
rawset(_G, 'router', router) -- set as global variable

local api = {}
rawset(_G, 'api', api)

router:bootstrap({timeout = 4, if_not_bootstrapped = true})

function api.echo(id, ...)
local bucket_id = router:bucket_id_strcrc32(id)


return router:call(bucket_id, 'read', 'echo', {...})
end

else
vshard.storage.cfg(cfg, names[NAME])

function echo(...)
return ...
end
end

box.once('access:v1', function()
box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

-- Configure the metrics module
metrics.cfg{labels = {alias = 'my-tnt-app'}}

-- Run the web server
local server = http_server.new('0.0.0.0', 8081)
server:route({path = '/metrics'}, http_metrics_handler)
server:start()
5 changes: 5 additions & 0 deletions examples/bench/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
storages:
storage_1_a: "tarantool-storage-1-a:3301"
storage_1_b: "tarantool-storage-1-b:3302"
storage_2_a: "tarantool-storage-2-a:3303"
storage_2_b: "tarantool-storage-2-b:3304"
95 changes: 95 additions & 0 deletions examples/bench/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: "3"
services:
webserver:
build: ./webserver
ports:
- "8080:8080"
- "8081:8081"
volumes:
- ./config.yaml:/etc/webserver/config.yaml
depends_on:
- tarantool-storage-1-a
- tarantool-storage-1-b
- tarantool-storage-2-a
- tarantool-storage-2-b
prometheus:
image: prom/prometheus:v2.53.3
ports:
- "9090:9090"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
- "--web.console.templates=/usr/share/prometheus/consoles"
- "--web.enable-remote-write-receiver"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=secret
volumes:
- ./grafana/provisioning:/etc/grafana/provisioning
- ./grafana/dashboards:/var/lib/grafana/dashboards
tarantool-router:
image: tarantool/tarantool:2.11.5-ubuntu20.04
ports:
- "12000:12000"
environment:
- CONFIG_FILE=/etc/tarantool/config.yaml
- TNT_NAME=router
volumes:
- ./config.yaml:/etc/tarantool/config.yaml
- ./config.lua:/etc/tarantool/config.lua
command: "tarantool /etc/tarantool/config.lua"
depends_on:
- tarantool-storage-1-a
- tarantool-storage-1-b
- tarantool-storage-2-a
- tarantool-storage-2-b
tarantool-storage-1-a:
image: tarantool/tarantool:2.11.5-ubuntu20.04
ports:
- "3301:3301"
environment:
- CONFIG_FILE=/etc/tarantool/config.yaml
- TNT_NAME=storage_1_a
volumes:
- ./config.yaml:/etc/tarantool/config.yaml
- ./config.lua:/etc/tarantool/config.lua
command: "tarantool /etc/tarantool/config.lua"
tarantool-storage-1-b:
image: tarantool/tarantool:2.11.5-ubuntu20.04
ports:
- "3302:3302"
environment:
- CONFIG_FILE=/etc/tarantool/config.yaml
- TNT_NAME=storage_1_b
volumes:
- ./config.yaml:/etc/tarantool/config.yaml
- ./config.lua:/etc/tarantool/config.lua
command: "tarantool /etc/tarantool/config.lua"
tarantool-storage-2-a:
image: tarantool/tarantool:2.11.5-ubuntu20.04
ports:
- "3303:3303"
environment:
- CONFIG_FILE=/etc/tarantool/config.yaml
- TNT_NAME=storage_2_a
volumes:
- ./config.yaml:/etc/tarantool/config.yaml
- ./config.lua:/etc/tarantool/config.lua
command: "tarantool /etc/tarantool/config.lua"
tarantool-storage-2-b:
image: tarantool/tarantool:2.11.5-ubuntu20.04
ports:
- "3304:3304"
environment:
- CONFIG_FILE=/etc/tarantool/config.yaml
- TNT_NAME=storage_2_b
volumes:
- ./config.yaml:/etc/tarantool/config.yaml
- ./config.lua:/etc/tarantool/config.lua
command: "tarantool /etc/tarantool/config.lua"
Binary file added examples/bench/docs/static/plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading