Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am mreiferson on github.
* I am snakes (https://keybase.io/snakes) on keybase.
* I have a public key whose fingerprint is D95F 8610 1A76 7410 4FD0 F177 D637 0BCE 91EC 464D
To claim this, I am signing this object:
#!/usr/bin/env python2.7
import sys
import logging
import functools
import time
import tornado.options
import tornado.ioloop
import nsq_data
import tornado.httpclient
import logging
import json
import urllib
import functools
_http_client = None
def http_client():
global _http_client
@mreiferson
mreiferson / check_aggregate_nsqd_depth.py
Created September 12, 2014 17:59
nagios aggregate depth check
#!/usr/bin/env python2.7
import sys
import logging
import functools
import time
import tornado.options
import tornado.ioloop
import nsq_data
from tornado.platform.twisted import TwistedIOLoop
import tornado.ioloop
from twisted.internet import defer, reactor
from twisted.application import service
import nsq
from nsq import Writer, Error
from nsq.async import AsyncConn
@mreiferson
mreiferson / gist:11403980
Last active August 29, 2015 14:00
new go-nsq API
func loop(inChan chan *nsq.Message) {
for _, msg := range inChan {
err := doWork(msg)
if err != nil {
msg.Requeue(-1)
continue
}
msg.Finish()
}
}
var exitSelectCases []reflect.SelectCase
for i := 0; i < readersCount; i++ {
r, err := nsq.NewReader(topic, channel)
if err != nil {
log.Fatalln("nsq.NewReader:", err)
}
r.SetMaxInFlight(2500)
for j := 0; j < workersPerReader; j++ {
@mreiferson
mreiferson / Dockerfile
Last active April 12, 2016 10:10
nsqd Dockerfile
FROM ubuntu
RUN apt-get -y install wget tar ca-certificates
RUN wget https://s3.amazonaws.com/bitly-downloads/nsq/nsq-0.2.23.linux-amd64.go1.1.2.tar.gz
RUN tar zxvf nsq-0.2.23.linux-amd64.go1.1.2.tar.gz
RUN mkdir -p /usr/local/bin
RUN cp /nsq-0.2.23.linux-amd64.go1.1.2/bin/nsqd /usr/local/bin
RUN mkdir -p /data
VOLUME ["/data"]
import functools
import sys
import logging
def exit_on_exception(method):
@functools.wraps(method)
def wrapped(*args, **kwargs):
try:
return method(*args, **kwargs)
@mreiferson
mreiferson / is_starved.py
Last active December 17, 2015 04:09
is_starved
def is_starved(conns):
for c in conns:
# the constant 0.85 is designed to *anticipate* starvation rather than wait for it
if c.in_flight > 0 and c.in_flight >= (c.last_ready * 0.85):
return True
return False