Skip to content

Instantly share code, notes, and snippets.

View nickva's full-sized avatar

Nick Vatamaniuc nickva

  • USA
View GitHub Profile
@nickva
nickva / ByteStuffing.md
Last active September 8, 2026 19:48
Byte stuffing couch_file

Byte stuffing like in https://datatracker.ietf.org/doc/html/rfc1662#section-4.2 except that we use a long byte prefix to make it easier to find and less chance of constantly escaping every random 255th byte

Pick some 7 bytes prefix P, something less likely to occur in erlang term_to_binary or utf8 encodings.

P = f5, f6, f7, f8, f9, fa, fb

One byte H (=fc) is the header byte. The header tag: P|H = f5, f6, f7, f8, f9, fa, fb, fc

Another X (=fd) is the escape header byte. The whole escape prefix is P|X = f5, f6, f7, f8, f9, fa, fb, fd

@nickva
nickva / reduce_group_bench.py
Created June 21, 2026 04:32
Benchmark CouchDB reduce view with buit-in reducer
#!/usr/bin/env python3
#
# Benchmark built-in reduce
# Example:
# reduce_group_bench.py --ndocs 200000
import time
import argparse
import requests
import statistics
@nickva
nickva / rep_bench.py
Created May 5, 2026 06:10
Benchmark replication
#!/usr/bin/env python3
"""
replicator benchmark
# 1kb docs, single replication
rep_bench.py --ndocs 50000 --doc-size 1024
# faster polling, don't recreate the source
rep_bench.py --keep-source --poll-interval 1 \
@nickva
nickva / view_bench.py
Created April 29, 2026 06:04
Build a CouchDB view and time it
#!/usr/bin/env python3
#
# view_bench.py --ndocs 100000 --doc-size 1500
#
import time
import argparse
import requests
TIMEOUT = 120
@nickva
nickva / cwb_bench2.erl
Created February 14, 2026 20:16
Erlang/OTP segfault
-module(cwb_bench2).
-export([run/5, status/1, stop/1]).
-export([init/1, terminate/2]).
-export([handle_call/3, handle_cast/2, handle_info/2]).
-behaviour(gen_server).
-define(HIBERNATE_DEFAULT, true).
-record(q, {
@nickva
nickva / view_cycle.py
Created February 7, 2026 17:32
Create and query couchdb views
#!/usr/bin/env python
import os
import sys
import time
import uuid
import random
import requests
import argparse
import configparser
@nickva
nickva / k6_couchdb_constant_arrival_view_query.js
Created February 7, 2026 17:31
couchdb k6 view query with constant arrival
//
// Examples:
// BENCH_RATE=500 BENCH_DURATION=20s BENCH_VIEW_LIMIT=16 k6 run ./$script.js
//
// config:set("log", "level", "warning").
//
import http from 'k6/http';
import encoding from 'k6/encoding';
@nickva
nickva / time_seq_histogram_mplib.py
Created January 10, 2026 06:57
Render CouchDB's new _time_seq response as a histogram
#!/usr/bin/env python3
# Render _time_seq response as a histogram using matplotlib
# Run as:
# http $DB/db/_time_seq | ~/scripts/time_seq_histogram_mplib.py
import json, sys
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
@nickva
nickva / bench_parse_revid.erl
Created October 14, 2025 18:34
RevId Parsing CouchDB Benchmark: decode_hex vs binary_to_integer(RevId, 16)
-module(bench_parse_revid).
-export([go/0]).
-define(REPEAT, 100).
go() ->
go([10, 100, 500, 1000, 2500]).
@nickva
nickva / topn_view.py
Created March 26, 2025 17:11
Try out topN/bottomN built-in reducers
#!/usr/bin/env python
# ./just_view.py 500 1000
import sys
import time
import random
import requests
TIMEOUT=120