Skip to content

Instantly share code, notes, and snippets.

View ochaton's full-sized avatar

Vladislav Grubov ochaton

  • Tarantool
  • Moscow, Russia
View GitHub Profile
@ochaton
ochaton / cluster-config-json-schema.lua
Last active September 6, 2024 11:49
Generate JSON schema for Tarantool's cluster configuration by @Totktonada
#!/usr/bin/env tarantool
local json = require('json')
local cluster_config = require('internal.config.cluster_config')
local scalars = {}
scalars.string = {
jsonschema = {
type = 'string',
@ochaton
ochaton / lib.rs
Created September 5, 2024 20:04
Rust stored Proc registration without Lua
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use tarantool::{self, session, tuple::Encode};
use mlua::Lua;
#[tarantool::proc]
fn add(left: i64, right: i64) -> i64 {
left + right
}
-- Tarantool 3.0.2-0-gf9e82c5 Darwin-arm64-RelWithDebInfo
local fiber = require 'fiber'
local clock = require 'clock'
local log = require 'log'
box.cfg{checkpoint_count = 1,listen=3301}
box.ctl.promote()
require 'jit'.on()
fiber.top_enable()
@ochaton
ochaton / cpu_limit.lua
Created April 28, 2024 01:08
PoC: cpu_limit method for luafun iterator inside Tarantool to allow automatic control of yields
--[[
cpu limit is like leaking bucket.
we say that we want to limit this iterator to consume ≤10% cpu.
Caller:
- ev(), real()
- gen_x(param_x, state_x)
- ev(), real()
local fiber = require 'fiber'
local clock = require 'clock'
local fun = require 'fun'
require 'jit'.on()
fiber.top_enable()
local COLLECT_INTERVAL = 1
fiber.create(function()
fiber.name("monitor")
{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","additionalProperties":false,"properties":{"fiber":{"type":"object","additionalProperties":false,"properties":{"io_collect_interval":{"type":"number","default":null},"too_long_threshold":{"type":"number","default":0.5},"top":{"type":"object","additionalProperties":false,"properties":{"enabled":{"type":"boolean","default":false}}},"slice":{"type":"object","additionalProperties":false,"properties":{"err":{"type":"number","default":1},"warn":{"type":"number","default":0.5}}},"worker_pool_threads":{"type":"number","default":4}}},"wal":{"type":"object","additionalProperties":false,"properties":{"queue_max_size":{"type":"integer","default":16777216},"dir_rescan_delay":{"type":"number","default":2},"dir":{"type":"string","default":"var/lib/{{ instance_name }}"},"ext":{"type":"object","properties":{"spaces":{"type":"object","additionalProperties":{"type":"object","additionalProperties":false,"properties":{"old":{"type":"boolean","default":false
require 'compat'.json_escape_forward_slash = 'new'
local log = require 'log'
local json = require 'json'
local netbox = require 'net.box'
local router = netbox.connect('127.0.0.1:4401')
log.info("call_raw: %s", json.encode(router:call('call_raw')))
log.info("call_noraw: %s", json.encode(router:call('call_noraw')))
--[[
@ochaton
ochaton / gist:8e3739ed220d306da08bff72e7b2e490
Created August 20, 2023 20:06
Tarantool checksums benchmarks
tarantool> require'tarantool'
---
- build: &0
target: Darwin-arm64-Release
options: cmake . -DCMAKE_INSTALL_PREFIX=/opt/homebrew/Cellar/tarantool/2.11.0_1
-DENABLE_BACKTRACE=TRUE
linking: dynamic
mod_format: dylib
flags: ' -fexceptions -funwind-tables -fasynchronous-unwind-tables -fno-common
-fopenmp -Wformat -Wformat-security -Werror=format-security -fstack-protector-strong
@ochaton
ochaton / scanner.lua
Created July 5, 2023 18:46
Index scanner for Tarantool
local msgpack = require 'msgpack'
local base64_encode = require 'digest'.base64_encode
local base64_decode = require 'digest'.base64_decode
---@alias scan.cursor string
---Encodes cursor to string
---@param index boxIndex
---@param tuple box.tuple
---@return string
@ochaton
ochaton / rmean.lua
Created July 1, 2023 17:57
Plain Lua implementation of Tarantool's rmean_collect
---Class rmean is plain-Lua implementation of Tarantool's rmean collector
---
---rmean provides window function mean with specified window size (default=5s)
---rmean well tested on 10K parallel running collectors
---
---rmean:collect(value) is lightning fast ≈ 1B calls per second with jit.on
---and ≈ 15M with jit.off
---
---rmean:mean() makes 10M calls per second with jit.off() and ≈50M calls with jit.on
---