Skip to content

Instantly share code, notes, and snippets.

package watchpool
import (
"context"
"sync"
"time"
)
// WatchPool is a shared container for watch channels that are closed to notify
// multiple observers of a change. It allows sharing the monitor goroutine
Test setup
==========
DO droplet with 8vcpu 32GB RAM 640GB SSD/
// Master (boltdb log store)
Running 10s test @ http://localhost:8500/v1/kv/foo
4 threads and 50 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 4.91ms 2.84ms 49.55ms 91.78%
-----BEGIN CERTIFICATE-----
MIICpzCCAk2gAwIBAgIUDWOb2bgBLZ+Vuqr7H0dlNxpyfoIwCgYIKoZIzj0EAwIw
FDESMBAGA1UEAxMJVGVzdCBDQSAxMB4XDTE4MDYxOTE2NDMyMFoXDTI4MDYxNjE2
NDMyMFowFDESMBAGA1UEAxMJVGVzdCBDQSAxMFkwEwYHKoZIzj0CAQYIKoZIzj0D
AQcDQgAEOF9GX0vk+fia1Es114uBi3w+4AK1k+VLvladnJQQzosePPLSnOdE36MY
/cYnc+hAWasoqGoZFFCt/xA7+B0HaaOCAXswggF3MA4GA1UdDwEB/wQEAwIBhjAP
BgNVHRMBAf8EBTADAQH/MGgGA1UdDgRhBF84YTpjNDozZjo2Mjo5MDo5NzoxMzo1
ODpiOTo4Zjo3NTpmYjplMDo1Yzo5Yjo2Nzo3YTplZjo2Nzo4YjozMjozNTo1Nzow
YjowMzpiYzpiNTphMzo5Zjo5YjozMjpkYTBqBgNVHSMEYzBhgF84YTpjNDozZjo2
Mjo5MDo5NzoxMzo1ODpiOTo4Zjo3NTpmYjplMDo1Yzo5Yjo2Nzo3YTplZjo2Nzo4
package main
import (
"bytes"
"compress/lzw"
"crypto/md5"
"encoding/gob"
"fmt"
"log"
"time"
@banks
banks / ecdh.go
Last active April 23, 2020 02:12
// ecdh implements a simple way to perform Diffie-Hellman Key Exchange using
// Curve25519 on the command line.
//
// NOTE: this is a toy for fun. Don't use it.
//
// See https://godoc.org/golang.org/x/crypto/curve25519 and
// https://cr.yp.to/ecdh.html for more info.
//
// The final shared secret given is the raw shared secret bytes from DH and is
// not typically suitable for direct use as an encryption key as it can leak
#! /bin/bash
# Sets up outgoing dummynet in pf firewall suitable for use to throttle outgoing network
# connections. gtihub.com/tylertreat/comcast is a much nicer tool but I couldn't get it to work due
# to shell issues and more - it seemed to only setup inbound rules in pf which don't affect outbound
# TCP connections in my tests.
TARGET=$1
PIPECFG=${2:-"plr 1"}
$ ./grpc_proxy_bug.sh
Putting /grpc_proxy_bug/001
OK
Putting /grpc_proxy_bug/002
OK
Putting /grpc_proxy_bug/003
OK
Putting /grpc_proxy_bug/004
OK
Putting /grpc_proxy_bug/005
bash-4.4$ export STEP=120
bash-4.4$ for i in $(seq 1 10 600); do START=$((1485176922 + i)); END=$((1485263322 + $i)); echo "$START - $END"; curl 2>/dev/null "http://prometheus.1.dblayer.com:9090/api/v1/query_range?query=cpu_usage_user%7Bhost%3D%22candidate.57%22%7D%20&start=$START&end=$END&step=$STEP" | jq '.data.result[0].values[] | .[1] | tonumber' | awk -v max=0 -v min=9999 '{ total += $1; count++; if($1>max){max=$1}; if($1<min){min=$1} } END { print " " total/count, max, min}'; done
1485176923 - 1485263323
45.4626 91.07730456963016 12.89468239168138
1485176933 - 1485263333
30.1437 86.16109881174854 10.058442152821929
1485176943 - 1485263343
30.1437 86.16109881174854 10.058442152821929
1485176953 - 1485263353
23.3495 71.28118644816615 6.88269494352532

Keybase proof

I hereby claim:

  • I am banks on github.
  • I am banksyw (https://keybase.io/banksyw) on keybase.
  • I have a public key ASD34ru5nha4p16hYT9Ye62vPO3FM-d3r3Is6xmFLhhH5Ao

To claim this, I am signing this object:

// On Macbook pro quad-core 2014 retina 15inch
Opts: {}
Batches of 1
Inserting 5000 docs took 52808.177948ms @ 94.6822834187 per second
Batches of 10
Inserting 5000 docs took 9779.50787544ms @ 511.27290901 per second
Batches of 200
Inserting 5000 docs took 1662.64986992ms @ 3007.23692097 per second
Opts: {'durability': 'soft'}
Batches of 1