This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
import sys | |
import logging | |
import functools | |
import time | |
import tornado.options | |
import tornado.ioloop | |
import nsq_data | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.httpclient | |
import logging | |
import json | |
import urllib | |
import functools | |
_http_client = None | |
def http_client(): | |
global _http_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
import sys | |
import logging | |
import functools | |
import time | |
import tornado.options | |
import tornado.ioloop | |
import nsq_data | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func loop(inChan chan *nsq.Message) { | |
for _, msg := range inChan { | |
err := doWork(msg) | |
if err != nil { | |
msg.Requeue(-1) | |
continue | |
} | |
msg.Finish() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++ { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import sys | |
import logging | |
def exit_on_exception(method): | |
@functools.wraps(method) | |
def wrapped(*args, **kwargs): | |
try: | |
return method(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder