Skip to content

Instantly share code, notes, and snippets.

View gist:a037931da033c133fdbc
### 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:
View check_aggregate_nsqd_depth.py
#!/usr/bin/env python2.7
import sys
import logging
import functools
import time
import tornado.options
import tornado.ioloop
import nsq_data
View nsq_data.py
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 Sep 12, 2014
nagios aggregate depth check
View check_aggregate_nsqd_depth.py
#!/usr/bin/env python2.7
import sys
import logging
import functools
import time
import tornado.options
import tornado.ioloop
import nsq_data
View gist:7975fa5c5203902a2304
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 Aug 29, 2015
new go-nsq API
View gist:11403980
func loop(inChan chan *nsq.Message) {
for _, msg := range inChan {
err := doWork(msg)
if err != nil {
msg.Requeue(-1)
continue
}
msg.Finish()
}
}
View gist:9945305
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 Apr 12, 2016
nsqd Dockerfile
View 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"]
View exit_on_exception.py
import functools
import sys
import logging
def exit_on_exception(method):
@functools.wraps(method)
def wrapped(*args, **kwargs):
try:
return method(*args, **kwargs)
View is_starved.py
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