Skip to content

Instantly share code, notes, and snippets.

View ochaton's full-sized avatar

Vladislav Grubov ochaton

  • Tarantool
  • Moscow, Russia
View GitHub Profile
--[[
This is handy module to set package.path and package.cpath
]]
local fio = require 'fio'
local soext = (jit.os == "OSX" and "dylib" or "so")
local ROCKS_LIB_PATH = '.rocks/lib/tarantool'
local ROCKS_LUA_PATH = '.rocks/share/tarantool'
require 'console'.listen('unix/:./tarantool.sock')
local fiber = require('fiber')
local log = require 'log'
local fun = require 'fun'
local fio = require 'fio'
local clock = require 'clock'
fun.grep('%.xlog', fio.listdir('.')):each(fio.unlink)
box.cfg{listen=3301, too_long_threshold=0.1,log_level=4}
#!/usr/bin/env tarantool
local fio = require 'fio'
local soext = (jit.os == "OSX" and "dylib" or "so")
local ROCKS_LIB_PATH = '.rocks/lib/tarantool'
local ROCKS_LUA_PATH = '.rocks/share/tarantool'
local LIB_TEMPLATES = { '?.'..soext, ROCKS_LIB_PATH .. '/?.'..soext }
local LUA_TEMPLATES = { '?.lua', '?/init.lua', ROCKS_LUA_PATH .. '/?.lua', ROCKS_LUA_PATH .. '/?/init.lua' }
@ochaton
ochaton / box.lua
Created September 28, 2022 11:00
EmmyLua for box.info
---@class BoxCfg
---@field listen string|number URI to bind tarantool
---@field read_only boolean (default: false) should this instance be RO
---@field replication_connect_quorum number (default: _cluster:len()) required number of connected replicas to start bootstrap
---@field replication_connect_timeout number (default: 30) timeout in seconds to expect replicas in replication to fail bootstrap
---@field replication string[] list of URI of replicas to connect to
---@field election_mode string (default: off) enables RAFT. Possible values: candidate, voter, off
---@field replication_synchro_quorum string|number (default: 1) number or formula of synchro quorum. possible: "N/2+1"
---@field wal_dir string path to dir with xlogs
---@field work_dir string path to work dir of tarantool
local fun = require 'fun'
local l337 = function(s)
return (s:lower():gsub('.', {
a = 'a', b = '8', c = 'c', d = 'd', e = 'e', f = 'f',
g = '6', h = '4', i = '9', j = '7', k = '0', l = '1',
m = '44', n = '11', o = '0', p = '17', q = '9', r = '12',
s = '5', t = '7', u = '4', v = '5', w = '22', x = '8', y = '7', z = '5',
}))
end
@ochaton
ochaton / compressor.go
Last active April 6, 2022 16:56
Just a tool to bench compression algorithms for your dataset
package main
import (
"flag"
"fmt"
"io"
"net/http"
"time"
gzip "github.com/klauspost/compress/gzip"
@ochaton
ochaton / tarantool_console_ps1.lua
Created March 23, 2022 19:38
Boost Tarantool Console
require'fiber'.self().storage.console.prompt = nil
getmetatable(require'fiber'.self().storage.console).__index.prompt = nil
local c = require 'clock' local f = require 'fiber' do
local eval = getmetatable(f.self().storage.console).__index.eval
local function timeit(s, ...)
f.self().storage.cmd_time=c.time()-s
return ...
end
local my_eval = function(...)
@ochaton
ochaton / onliner.lua
Created January 17, 2022 19:28
Adds fun.yield to tarantool
local fun = require 'fun' local iter = fun.iter local wrap = fun.wrap local sleep = require 'fiber'.sleep local function yield_gen_x(i, state_x, ...) if state_x == nil then return nil end return {i, state_x}, ... end local function yield_gen(param, state) local n, no, gen_x, param_x = param[1], param[2], param[3], param[4] local i, state_x = state[1], state[2] if i % n == 0 then sleep(no) end return yield_gen_x(i+1, gen_x(param_x, state_x)) end local function yield1(n, no, gen, param, state) assert(n >= 0, "invalid first argument to yield") assert(no >= 0, "invalid second argument to yield") return wrap(yield_gen, { n, no, gen, param }, { 0, state }) end local function method_yield(self, n, no) return yield1(n, no or 0, self.gen, self.param, self.state) end getmetatable(iter{}).__index.yield = method_yield getmetatable(iter{}).__index.sleep = method_yield local function export_yield(n, no, gen, param, state) return yield1(n, no or 0, iter(gen, param, state)) end fun.yield = export_yield fun.sleep = export_yie
@ochaton
ochaton / .tarantoolctl
Created September 9, 2021 18:14
PoC: Tarantool logical replication ?
local workdir = './.tnt/'
require('fio').mkdir(workdir)
default_cfg = {
pid_file = workdir,
wal_dir = workdir,
snap_dir = workdir,
vinyl_dir = workdir,
logger = workdir,
}
@ochaton
ochaton / bad_tarantool.sh
Created July 6, 2021 16:45
Monitoring fiber of latency of single ev_once
> tarantool -l fiber -l clock -e 'fiber.create(function() while true do while clock.time() < fiber.time()+0.1 do end fiber.sleep(0.01) end end)' test.lua
entering the event loop
e:100.011µs p:0.017µs t:99.998µs
e:100.042µs p:0.010µs t:100.035µs
e:100.013µs p:0.015µs t:100.004µs
e:100.005µs p:0.006µs t:99.994µs
e:100.007µs p:0.004µs t:99.996µs
e:100.010µs p:0.009µs t:99.993µs
e:100.012µs p:0.016µs t:100.000µs
e:100.009µs p:0.050µs t:99.999µs