Skip to content

Instantly share code, notes, and snippets.

View kolotaev's full-sized avatar
🦔
githubbing...

kolotaev

🦔
githubbing...
View GitHub Profile
@rkumar
rkumar / gist:445735
Created June 20, 2010 10:47
ruby's OptionParser to get subcommands
#!/usr/bin/env ruby -w
## Using ruby's standard OptionParser to get subcommand's in command line arguments
## Note you cannot do: opt.rb help command
## other options are commander, main, GLI, trollop...
# run it as
# ruby opt.rb --help
# ruby opt.rb foo --help
# ruby opt.rb foo -q
# etc
@jboner
jboner / latency.txt
Last active July 7, 2024 21:35
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
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 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@apeckham
apeckham / Gemfile
Created October 25, 2012 20:34
simple sinatra-synchrony/postgres example
source :rubygems
gem 'thin'
gem 'sinatra-synchrony'
gem 'em-pg-client', require: %w'pg/em em-synchrony/pg'
gem 'rack-contrib'
gem 'rspec'
gem 'rack-test'
@chanks
chanks / gist:7585810
Last active June 22, 2024 19:01
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@jjwatt
jjwatt / coolquery.clj
Last active September 7, 2019 09:37
core.async database query fn
(ns
#^{:author "Jesse Wattenbarger"
:doc "pulled out of a production program for gist."}
coolquery.core
(:gen-class)
(:require [clojure.java.io :as io]
[clojure.core.async :as a :refer
[chan go go-loop close! <!! <! >! >!!]]
[jdbc.core :as jdbc] ;; good jdbc interop
))
@terrybleger
terrybleger / async.kt
Last active April 5, 2020 17:43
Vertx - Quasar - Kotlin
package util.func
import co.paralleluniverse.fibers.*
import co.paralleluniverse.strands.SuspendableCallable
import co.paralleluniverse.strands.SuspendableRunnable
import io.vertx.core.Context
import io.vertx.core.Future
import io.vertx.core.Vertx
import java.util.concurrent.Executor
@wfaler
wfaler / bind-consul.sh
Created September 9, 2015 19:01
use consul as DNS for local services, fronted by Bind for the rest
sudo apt-get install bind9 bind9utils bind9-doc
wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip
/etc/bind/named.conf.options:
options {
directory "/var/cache/bind";
recursion yes;
allow-query { localhost; };
forwarders {
@Faheetah
Faheetah / Jenkinsfile.groovy
Last active June 17, 2024 15:05
Jenkinsfile idiosynchrasies with escaping and quotes
node {
echo 'Results included as an inline comment exactly how they are returned as of Jenkins 2.121, with $BUILD_NUMBER = 1'
echo 'No quotes, pipeline command in single quotes'
sh 'echo $BUILD_NUMBER' // 1
echo 'Double quotes are silently dropped'
sh 'echo "$BUILD_NUMBER"' // 1
echo 'Even escaped with a single backslash they are dropped'
sh 'echo \"$BUILD_NUMBER\"' // 1
echo 'Using two backslashes, the quotes are preserved'
sh 'echo \\"$BUILD_NUMBER\\"' // "1"
@grrywlsn
grrywlsn / cloud-init
Created July 5, 2016 23:53
cloud-init script for AWS CentOS to use Ansible-Pull on startup
#!/bin/bash
# Set this script as the AWS user-data for a fresh CentOS AMI
# It will be run on startup, and logs to /var/log/cloud-init.log
rpm -iUvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y update
yum -y install epel-release
yum -y install ansible
yum -y install git
mkdir -p /home/centos/.ssh
cat <<EOF > /home/centos/.ssh/id_rsa
@zloster
zloster / echo-in-console-instruction-count.md
Created November 17, 2016 15:24
How much work the poor CPU needs to do when we echo 4-characters string in the Linux console?

And the answer is:

688471 instructions

--@--:~$ uname -a
Linux 3.13.0-101-generic #148-Ubuntu SMP Thu Oct 20 22:09:17 UTC 2016 i686 i686 i686 GNU/Linux
--@--:~$ sudo perf stat echo test
test