Skip to content

Instantly share code, notes, and snippets.

View nickva's full-sized avatar

Nick Vatamaniuc nickva

  • USA
View GitHub Profile
@nickva
nickva / remsh.erl
Last active May 23, 2024 17:09
recon trace return errors only
> recon_trace:calls({fabric, design_docs, fun(_) -> exception_trace() end}, 10, [
{formatter, fun
({trace, _, exception_from, MFA, Err}) -> io_lib:format("|~p:~p|~n", [MFA,Err]);
({trace, _, return_from, MFA, {IsOk,_}=Res}) when IsOk =/= ok -> io_lib:format("|~p:~p|n", [MFA,Res]);
(_) -> ""
end}
]).
% ./enc
=ERROR REPORT==== 22-May-2024::15:14:05.001026 ===
beam/beam_load.c(607): Error loading function rebar:log/3: op init y:
no specific operation found
escript: exception error: undefined function rebar:main/1
in function escript:run/2 (escript.erl, line 904)
in call from escript:start/1 (escript.erl, line 418)
in call from init:start_it/1
@nickva
nickva / example.erl
Created May 20, 2024 15:51
New Erlang json module, sigils and triple quoted strings
> json:decode(~"""
{"a":"b", "c":true, "d":42, "e":1.2, "f":false, "g":null}
""").
#{<<"a">> => <<"b">>,<<"c">> => true,<<"d">> => 42,
<<"e">> => 1.2,<<"f">> => false,<<"g">> => null}
@nickva
nickva / ddoc_cache_bench.erl
Created February 16, 2024 20:54
Apache CouchDB ddoc_cache_lru benchmark
% Benchmark module for ddoc_cache_lru
%
% Benchmark opening and closing (evicting) a bunch of random dbs/ddocs.
%
% Times are measured in microseconds. Best (minimum) results are returned for each
% of the N cases.
%
-module(ddoc_cache_bench).
@nickva
nickva / couch_event_bench.erl
Created February 11, 2024 06:33
CouchDB Event Server Benchmark
% Benchmark module for couch_event_server
%
% Benchmark registering/unregistering N listeners for N dbs. Then benchmark
% sending 10 events from concurrent proceses for each of the Db and measure
% event latency: how long it took for the event to be delivered to the
% listener.
%
% Times are measured in microseconds. Best (minimum) results are returned for each
% of the N cases.
%
@nickva
nickva / findlimit.py
Last active January 30, 2024 06:18
Mango execution stats checker
#!/usr/bin/env python
import json
import time
import requests
import string
import random
S = requests.session()
@nickva
nickva / chnagesrevtree.sh
Created January 4, 2024 22:56
Various changes feed parameters for Apache CouchDB
#!/bin/bash
http -q delete $DB/db
http -q put $DB/db
http post $DB/db/_bulk_docs new_edits:='false' docs:='[{"_id":"d1", "_revisions":{"start":2, "ids":["x", "z"]}, "data":1}, {"_id":"d1", "data":2, "_revisions":{"start":2, "ids":["y", "z"]}}, {"_id":"d1", "data":3, "_deleted":true, "_revisions":{"start":2, "ids":["w", "z"]}}]'
http -q put $DB/db/d1/att2y'?rev=2-y' data=2y
http -q put $DB/db/d1/att2x'?rev=2-x' data=2x
echo "Without a filter with atts"
@nickva
nickva / multiuser.py
Last active November 9, 2023 04:34
Test script to generate a lot of CouchDB regular and admin users
#!/usr/bin/env python
#
# make && ./dev/run -n 1 --admin=adm:pass
# ./multiuser.py --users-scheme=simple --users-salt="abc" --users-hash-sha1 --tries 100
import copy
import sys
import time
import threading
import os
@nickva
nickva / distblockleak.erl
Created November 7, 2023 06:17
Reproducer for a binary memory leak across a dist channel on OTP 24+
%
% $ erl -name otp252@127.0.0.1
% > c(distblockleak).
%
% $ erl -name otp251@127.0.0.1
% > c(distblockleak), distblockleak:go('otp252@127.0.0.1', "./junk.bin", 10000, 100, 200).
%
-module(distblockleak).
@nickva
nickva / ioblock.erl
Last active October 31, 2023 05:53
Reproducer attempt for process_info slowdown in OTP 25
%% Reproducer attempt for https://github.com/erlang/otp/issues/7801
%% It's supposed to model the couch_file.erl from Apache CouchDB
%%
%% Example run:
%% c(ioblock), ioblock:go("./junk.bin", 8192, 60, 4000).
%% - Create a temporary junk.bin file with 8GB of random data
%% - Spawn 60 gen_servers to handle preads from the file
%% - Spawn 4000 caller processes to call the servers with pread commands
%%
%% Note: run the first time without measuring to create the larger file.