Skip to content

Instantly share code, notes, and snippets.

"""
makes text read like it was written by a drunk person
er, makes txet rea dlike i twas rwitten by a durnk persob
"""
import random
import sys
drinks = float(sys.argv[1])
@tkaemming
tkaemming / run-redis-cluster.py
Last active December 11, 2015 20:40
script to run n redis servers
import os
import signal
import subprocess
import sys
import tempfile
import time
processes = set()
@rbranson
rbranson / gist:038afa9ad7af3693efd0
Last active September 29, 2016 17:44
Disaggregated Proxy & Storage Nodes

The point of this is to use cheap machines with small/slow storage to coordinate client requests while dedicating the machines with the big and fast storage to doing what they do best. I found that request coordination was contributing to about half the CPU usage on our Cassandra nodes, on average. Solid state storage is quite expensive, nearly doubling the cost of typical hardware. It also means that if people have control over hardware placement within the network, they can place proxy nodes closer to the client without impacting their storage footprint or fault tolerance characteristics.

This is accomplished in Cassandra by passing the -Dcassandra.join_ring=false option when the process is started. These nodes will connect to the seeds, cache the gossip data, load the schema, and begin listening for client requests. Messages like "/x.x.x.x is now UP!" will appear on the other nodes.

There are also some more practical benefits to this. Handling client requests caused us to push the NewSize of the heap up

(6fbda187737cc2cd)ted@aventador-3 % python remove-consumer.py --zookeeper $ZOOKEEPER tkaemming
/consumers/tkaemming (created 1 day, 3:21:37.186777 ago, modified 1 day, 3:21:37.186777 ago, version 0)
/consumers/tkaemming/offsets (created 1 day, 3:21:27.186777 ago, modified 1 day, 3:21:27.186777 ago, version 0)
/consumers/tkaemming/offsets/activity-metrics (created 1 day, 3:21:27.186777 ago, modified 1 day, 3:21:27.186777 ago, version 0)
/consumers/tkaemming/offsets/activity-metrics/3-1 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/activity-metrics/3-0 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/activity-metrics/1-1 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/activity-metrics/1-0 (created 1 day, 3:21:26.186777 ago, modified 0:31:03.186777 ago, version 1293)
/consumers/tkaemming/offsets/ac
import uuid
alphabet = (
'!"#$%&\'()*+,-./0123456789:;<=>?@'
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'[\\]^_`'
'abcdefghijklmnopqrstuvwxyz{|}~'
)
@tkaemming
tkaemming / namedstruct.py
Created July 14, 2012 18:48
named structs
#!/usr/bin/env python
from collections import namedtuple
from struct import Struct
class NamedStruct(Struct):
def __init__(self, name, fields, byteorder=None):
fmt = (byteorder or '') + ''.join(field[0] for field in fields)
super(NamedStruct, self).__init__(fmt)
self.namedtuple = namedtuple(name, (field[1] for field in fields))
@tkaemming
tkaemming / gist:3069262
Created July 8, 2012 04:13
__repr__ with added attributes
def attribute_repr(*attributes):
"""
Example Usage:
>>> class Foo(object):
... __repr__ = attribute_repr('pk', 'slug')
<foo.models.Foo at 0x100614c50: pk=1, slug=foo>
"""
def _repr(self):
pairs = ('%s=%s' % (attribute, repr(getattr(self, attribute, None))) for attribute in attributes)
return u'<%s.%s at 0x%x: %s>' % (self.__class__.__module__, self.__class__.__name__,
@jboner
jboner / latency.txt
Last active April 25, 2024 01:18
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
@tkaemming
tkaemming / autocache.py
Created April 20, 2012 20:06
self-versioning and argument-hashing cache decorator for python (django/flask)
#!/usr/bin/env python
"""
Self-versioning and argument-hashing cache decorator for deterministic functions.
Designed to be extensible and API-compliant with Django and Flask cache backends.
For examples and caveats, see the bottom of the file.
Ted Kaemming: https://github.com/tkaemming
Mike Tigas: https://github.com/mtigas
"""
@tkaemming
tkaemming / controlchars.py
Created March 12, 2012 22:36
template tag to strip basic unicode control characters (unprintables, usually entered as artifacts of bad encoding/decoding from iso-8859 subsets like windows-1252) from template output
import re
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
CONTROL_CHARACTERS = re.compile(r'([\x00-\x1f\x7f-\x9f])*')