Skip to content

Instantly share code, notes, and snippets.

@szaydel
szaydel / active-zio-ios-by-pool-q.d
Last active January 2, 2019 16:07
OpenZFS write throttling observations and other observations around the ZIO pipeline. New write throttle in OpenZFS is well explained in this post by Adam: http://blog.delphix.com/ahl/2014/tuning-openzfs-write-throttle/. These snippets are borrowing
#!/usr/sbin/dtrace -qCs
#define UPPER_THRESHOLD 100
/* See zio.h line 147 or thereabout */
enum zio_priority {
ZIO_PRIORITY_SYNC_READ,
ZIO_PRIORITY_SYNC_WRITE, /* ZIL */
ZIO_PRIORITY_ASYNC_READ, /* prefetch */
ZIO_PRIORITY_ASYNC_WRITE, /* spa_sync() */
ZIO_PRIORITY_SCRUB, /* asynchronous scrub/resilver reads */
@ioguix
ioguix / btree_bloat.sql
Last active March 28, 2018 18:12
B-tree index bloat estimation
/* The bloat estimation queries moved to this respository:
* https://github.com/ioguix/pgsql-bloat-estimation
*/
@jberkus
jberkus / gist:6b1bcaf7724dfc2a54f3
Last active January 7, 2024 21:26
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
#!/usr/bin/env python
# Quick and dirty demonstration of CVE-2014-0160 by
# Jared Stafford (jspenguin@jspenguin.org)
# Modified so that it finds cookies
import sys
import struct
import socket
import time
import select
WITH btree_index_atts AS (
SELECT nspname, relname, reltuples, relpages, indrelid, relam,
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
indexrelid as index_oid
FROM pg_index
JOIN pg_class ON pg_class.oid=pg_index.indexrelid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
JOIN pg_am ON pg_class.relam = pg_am.oid
WHERE pg_am.amname = 'btree'
),
@mmitchel
mmitchel / freebsd10-gce.txt
Last active April 21, 2019 02:03
Prepare FreeBSD 10 for Google Compute Engine
I was able to install FreeBSD on GCE in a very direct way, without the hurdles of Qemu, gcutil, and the FreeBSD installer. All are great tools, but I think my apporach is somewhat more suitable for GCE, or at least much simpler. Much of this is well-known practice for installing manually, with some fluff for managing it as a disk image, as well as the few odd networking requirements of GCE (MTU and netmask).
My basic approach is to:
* Use my FreeBSD machine at home to build a self-hosting "rescue" disk image for GCE.
* Start a temporary Linux machine in GCE from a provided image.

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
L2 cache reference ........................... 7 ns                     14x L1 cache
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns                     20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs 4X memory

@aphyr
aphyr / -log
Last active December 22, 2015 02:19
In http://www.datastax.com/dev/blog/row-level-isolation and
http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2, Datastax
asserts that batch updates to multiple cells in a single row are
guaranteed to be isolated from concurrent batches:
"Cassandra 1.1 guarantees that if you update both the login and password in the
same update (for the same row key) then no concurrent read may see only a
partial update."
"...the guarantee is that the new login cannot be persisted without the new
@aras-p
aras-p / preprocessor_fun.h
Last active April 28, 2024 15:25
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,