Skip to content

Instantly share code, notes, and snippets.

View nickva's full-sized avatar

Nick Vatamaniuc nickva

  • USA
View GitHub Profile
@nickva
nickva / filebench.erl
Last active May 9, 2023 04:08
Silly benchmark reading a block in a loop and measuring the average across multiple runs
%> filebench:all("...data.../filebench.couch").
% * bsize: 65536 pread: 11 couch_file pread: 74 write: 465 couch_file append_bin: 477
% * bsize: 16384 pread: 8 couch_file pread: 49 write: 218 couch_file append_bin: 277
% * bsize: 4096 pread: 9 couch_file pread: 41 write: 197 couch_file append_bin: 236
% * bsize: 1024 pread: 11 couch_file pread: 37 write: 183 couch_file append_bin: 222
%
-module(filebench).
@nickva
nickva / distbench.erl
Last active September 7, 2023 15:30
Ping-pong across dist with N parallel workers
%
% $ erl -name n1@127.0.0.1
%
% $ erl -name n2@127.0.0.1
% (n2@127.0.0.1)2> dist_perf:go('n1@127.0.0.1').
-module(distbench).
-export([go/1, go/2, go/3, stop/0, gc/0, stats/1]).
@nickva
nickva / fixalloc.erl
Last active August 29, 2024 12:24
Erlang 24 and 25 fix_alloc memory leak
%
% Run on Erlang 24+
%
% (MFatags true is to enable instrumentation for fix_alloc)
%
% $ erl -name n1@127.0.0.1 +MFatags true
% (n1@127.0.0.1)>
%
% $ erl -name n2@127.0.0.1 +MFatags true
% (n2@127.0.0.1)2> c(fixalloc), fixalloc:go('n1@127.0.0.1').
@nickva
nickva / quickjs_vs_sm91.md
Created February 27, 2023 19:58
Overhead comparison QuickJS vs Spidermonkey 91. Measure process startup and context init

Spidermonkey (91), QuickJS (2021-03-27)

Intel MacOS SM91

% ./configure --dev --spidermonkey-version 91 && make
% TIMEFMT=$'Total (sec): \t%*E\nMax RSS(kb): \t%M\n'
% time ./couchjs
@nickva
nickva / xref_custom.erl
Created January 5, 2023 20:03
Run Erlang XRef Ignoring Some Modules
xref:stop(s).
xref:start(s).
xref:set_default(s, [{verbose, false}, {warnings, false}]).
xref:add_release(s, "./src").
xref:add_release(s, code:lib_dir(), {name, otp}).
f().
IgnorePrefixes = [
"hipe", "ibrowse", "hyper", "meck", "metrics", "parse_trans", "eunit_test", "hackney",
@nickva
nickva / playing_around.erl
Created December 23, 2022 19:35
Luerl for CouchDB Views
1> application:start(luerl),
1> F1 = "function(doc) emit('key1', doc) \n emit('key2', 'val2') end",
1> F2 = "function(doc) emit('key3', 'val3') end",
1> S0 = luerl_sandbox:init(),
1> {_, S1} = luerl:do("emits = {} \n function emit(k, v) \n table.insert(emits, {k, v}) end", S0),
1> {ok, C1, S2} = luerl:load("f = " ++ F1 ++ " \n f(...) \n return emits", S1),
1> {ok, C2, S3} = luerl:load("f = " ++ F2 ++ " \n f(...) \n return emits", S2),
1> {R1, _} = luerl:call_chunk(C1, [#{<<"_id">> => <<"1">>, <<"a">> => <<"b">>}], S3),
1> {R2, _} = luerl:call_chunk(C2, [#{<<"_id">> => <<"1">>, <<"a">> => <<"b">>}], S3),
1> #{<<"r1">> => R1, <<"r2">> => R2}.
@nickva
nickva / viewsize.py
Last active December 7, 2022 18:37
CouchDB View Benchmark
#!/usr/bin/env python
# still python2, sorry, old script
# pip install CouchDB
# ./viewsize.py
# file active external dtavg
# 18080120 17607050 14984706 45.973
import argparse
import sys
@nickva
nickva / dbcreate.py
Created November 28, 2022 18:08
Apache CouchDB DB Stampede
#!/usr/bin/env python
# Uses CouchDB (pip install CouchDB)
import sys, couchdb, time, os, uuid, argparse, random, traceback
from multiprocessing.dummy import Pool as ThreadPool
DB_URLS = [
'http://adm:pass@localhost:15984',
'http://adm:pass@localhost:25984',
@nickva
nickva / large_doc_compact_multiple_updates.sh
Created November 13, 2022 04:00
CouchDB doc update and delete script
#!/bin/bash
set -e
URL=http://adm:pass@localhost:15984
DB=${URL}/dbx
CFG=${URL}/_node/_local/_config
TMPFILE=/tmp/couch_largehex
DOCSIZE=100
@nickva
nickva / large_doc_compact.sh
Created November 11, 2022 20:04
couchdb smoosh doesn't trigger compaction
#!/bin/bash
set -e
URL=http://adm:pass@localhost:15984
DB=${URL}/dbx
CFG=${URL}/_node/_local/_config
DOC=doc1
TMPFILE=/tmp/couch_largehex