Skip to content

Instantly share code, notes, and snippets.

View nickva's full-sized avatar

Nick Vatamaniuc nickva

  • USA
View GitHub Profile
@nickva
nickva / replicate_att.sh
Created February 7, 2025 02:47
CouchDB replicate attachment twice
#!/bin/sh
# Create test DBs
echo "***** SETTING UP DBS *****"
curl -s -XDELETE 'http://adm:pass@localhost:15984/source'
curl -s -XDELETE 'http://adm:pass@localhost:15984/target'
curl -s -XPUT 'http://adm:pass@localhost:15984/source'
echo '{
@nickva
nickva / k6_couchdb_constant_arrival.js
Created February 4, 2025 15:12
CouchDB K6 script
//
// Examples:
// 1) Run all secenarios for 30sec with given user/pass:
// $ BENCH_DURATION=30s BENCH_USER=adm BENCH_PASS=pass run k6.js
// 2) Run just doc_update
// $ BENCH_SCENARIOS=doc_update k6 run $script.js
// 3) Run just doc_get at 10 rps, starting with 25k docs of 64KB each:
// $ BENCH_DOCS=25000 BENCH_SCENARIOS=doc_get BENCH_GET_RATE=10 k6 run $script.js
import http from 'k6/http';
@nickva
nickva / bench.erl
Created January 28, 2025 00:53
Benchmark couch work queue
-module(bench).
-export([main/1]).
producer(Q) ->
receive
{produce, Pid, N, Size} ->
{ok, Dt} = produce(Q, N, erlang:monotonic_time(), Size),
Pid ! {produced, Dt},
producer(Q)
@nickva
nickva / create_and_poll_reps.py
Created October 14, 2024 17:02
Create and monitor Apache CouchDB replication documents
#!/usr/bin/env python
# Run with an n=1 dev/run test cluster
# Needs python 3.7 minimum
#
# $ virtualenv -p python3 venv3
# $ . venv3/bin/activate
# $ pip install requests
# make && ./dev/run -n 3 --with-haproxy --admin=adm:pass
@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}
]).
@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"