• Stars
    star
    380
  • Rank 112,766 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Nydus is a Python toolkit for managing database connections and routing operations, primarily for Redis

Nydus

Generic database utilities, including connection clustering and routing so you can scale like a pro.

The following example creates a Redis connection cluster which will distribute reads and writes based on a simple modulus lookup of the hashed key:

from nydus.db import create_cluster

redis = create_cluster({
    'backend': 'nydus.db.backends.redis.Redis',
    'router': 'nydus.db.routers.keyvalue.PartitionRouter',
    'hosts': {
        0: {'db': 0},
        1: {'db': 1},
        2: {'db': 2},
    }
})

res = redis.incr('foo')

assert res == 1

nydus.db.create_cluster

The create_cluster function is a simple helper to configure a Cluster based on a simple dict config.

There are two required keyword arguments:

  • backend: full path to the backend class, which should extend nydus.db.backends.BaseConnection.

  • hosts: a dictionary, where the key is an ordered numeric value, and the result is a dict of connection options.

    (the keys are numeric values simply for readability in configuration)

  • defaults: a dictionary of default settings for all hosts to inherit from.

Optionally, you may also specify a value for router, which is the full path to the router class, which must extend nydus.db.routers.BaseRouter.

Distributed Queries

In some cases you may want to execute a query on many nodes (in parallel). Nydus has built-in support for this when any routing function returns a cluster of nodes:

from nydus.db import create_cluster
>>>
# by not specifying a router all queries are executed on all hosts
redis = create_cluster({
    'backend': 'nydus.db.backends.redis.Redis',
    'hosts': {
        0: {'db': 0},
        1: {'db': 1},
        2: {'db': 2},
    }
})
>>>
# map the query over all connections returned by the default router
res = redis.incr('foo')
>>>
assert type(res) == list
assert len(res) == 3

You can also map many queries (utilizing an internal queue) over connections (again, returned by the router):

with redis.map() as conn:
    results = [conn.incr(k) for k in keys]

As of release 0.5.0, the map() function now supports pipelines, and the included Redis backend will pipeline commands wherever possible.

Redis

Nydus was originally designed as a toolkit to expand on the usage of Redis at DISQUS. While it does provide a framework for building clusters that are not Redis, much of the support has gone into providing utilities for routing and querying on Redis clusters.

You can configure the Redis client for a connection by specifying it's full path:

redis = create_cluster({
    'backend': 'nydus.db.backends.redis.Redis',
    'hosts': {
        0: {'db': 0},
    },
})

The available host options are:

  • host
  • port
  • db
  • timeout
  • password
  • identifier

The Redis client also supports pipelines via the map command. This means that all commands will hit servers at most as of once:

with redis.map() as conn:
    conn.set('a', 1)
    conn.incr('a')
    results = [conn.get('a'), conn.get('b')]
results['a'] == 2
results['b'] == None

Simple Partition Router

There are also several options for builtin routing. The easiest is a simple partition router, which is just a simple hash on the key:

redis = create_cluster({
    'backend': 'nydus.db.backends.redis.Redis',
    'router': 'nydus.db.routers.keyvalue.PartitionRouter',
    'hosts': {
        0: {'db': 0},
    },
})

Consistent Hashing Router

An improvement upon hashing, Nydus provides a Ketama-based consistent hashing router:

redis = create_cluster({
    'backend': 'nydus.db.backends.redis.Redis',
    'router': 'nydus.db.routers.keyvalue.ConsistentHashingRouter',
    'hosts': {
        0: {'db': 0},
    },
})

Round Robin Router

An additional option for distributing queries is the round robin router:

redis = create_cluster({
    'backend': 'nydus.db.backends.redis.Redis',
    'router': 'nydus.db.routers.RoundRobinRouter',
    'hosts': {
        0: {'db': 0},
    },
})

Pycassa

Basic connection management for pycassa (Cassandra) clusters is supported, but we use a non-standard syntax for creating clusters as routing behavior and per-connection options are not useful in this context:

pycassa = create_cluster({
    'backend': 'nydus.db.backends.pycassa.Pycassa',
    'hosts': ['localhost'],
    'keyspace': 'test',
})

Note

Pycassa handles routing of hosts internally, which means things like map have no affect.

More Repositories

1

gargoyle

Feature switches in Django
Python
747
star
2

django-bitfield

A BitField extension for Django Models
Python
378
star
3

disqus-react

A React component for Disqus
JavaScript
369
star
4

DISQUS-API-Recipes

Cook all the things!
PHP
287
star
5

django-mailviews

Class-based email views for the Django framework, including a message previewer.
Python
269
star
6

overseer

A status board built with Django
Python
257
star
7

gutter

Fully featured Python feature switch toolkit
Python
226
star
8

nexus

A centralized, pluggable admin app for Django
Python
204
star
9

disqus-python

Disqus API bindings for Python
Python
162
star
10

python-phabricator

Python bindings for Phabricator
Python
159
star
11

django-db-utils

Utilities for your Django Database
Python
159
star
12

disqus-php

Disqus API bindings for PHP
PHP
146
star
13

django-modeldict

Python
132
star
14

sharding-example

Example of sharding tools used at Disqus
Python
112
star
15

django-perftools

Performance monitoring tools for Django
Python
110
star
16

backbone.uniquemodel

Backbone.js plugin for ensuring unique model instances across your app
JavaScript
98
star
17

porkchop

Simple HTTP-based system information server
Python
93
star
18

durabledict

Dictionary-style access to different types of models.
Python
85
star
19

postfix-stats

Simple threaded stats aggregator for Postfix
Python
76
star
20

grunt-smartrev

A "smart" file versioner for production environments which takes inter-file dependencies into account automatically.
JavaScript
75
star
21

orbital

Orbital is a real-time map built on top of Websockets and ZeroMQ.
JavaScript
69
star
22

disqus-wordpress

Legacy WordPress plugin 1.x - 2.x. Go to disqus/disqus-wordpress-plugin for current version -
PHP
68
star
23

toronado

fast lxml-based stylesheet inliner
Python
60
star
24

disqus-install-examples

Installation Examples for Disqus
HTML
55
star
25

mule

Mule is a distributed test runner for Python
Python
51
star
26

gutter-django

Python
45
star
27

menagerie

ZooKeeper-backed Django settings interface.
Python
42
star
28

disqus-postgres

Python
39
star
29

fpm-recipes

Makefile
39
star
30

grockets

Realtime streaming graphite data via socket.io and node.js
JavaScript
38
star
31

nose-performance

A plugin for Nose for running performance tests
Python
34
star
32

zumanji

A web interface for aggregating results from nose-performance
JavaScript
33
star
33

disqus-wordpress-plugin

WordPress plugin for Disqus (Latest version)
TypeScript
33
star
34

nagios-plugins

Nagios plugins written at Disqus
Python
30
star
35

channels

A demo of a modern forum powered by DISQUS
JavaScript
30
star
36

nydus-django

Python
29
star
37

playa

An audio playing web service
Python
27
star
38

sentry-graphite

An extension for Sentry that increments a key in graphite based on the error.
Python
27
star
39

disqus-arcanist

Arcanist extensions by Disqus
PHP
26
star
40

php-disqus

Old PHP bindings for Disqus
PHP
22
star
41

porkchop-plugins

Plugins for Porkchop
Python
18
star
42

nose-socket-whitelist

nose plugin that provides control over what socket connections can be opened during test execution
Python
17
star
43

disqus.github.com

Python
16
star
44

codebox

Code Sharing for Teams
Python
14
star
45

nose-template-usage

Template usage reports for testing Django applications with Nose.
Python
13
star
46

mockhttp

Python
13
star
47

django-patches

A collection of patches of various changes in Django used by Disqus
12
star
48

pgshovel

A change data capture system for PostgreSQL
Python
11
star
49

pg_audit

Audit PostgreSQL tables in an automated fashion.
10
star
50

docker-nginx

some dockerfiles for some nginx
Dockerfile
9
star
51

graphite-reporter-agent

Java Agent for Cassandra's Metrics' Graphite Reporter
Java
9
star
52

facebook-python-sdk

Facebook Platform Python SDK
Python
8
star
53

django-metaredirect

META-tag and JavaScript based generic redirect views for maintaining HTTP referrers.
Python
8
star
54

psycopg2-managed-connection

Thread-safe connection manager for psycopg2 connections.
Python
8
star
55

pg_partition

Partition management for PostgreSQL
7
star
56

fastly-slurper

Slurps delicious fastly logs. Mmm.
Python
7
star
57

django-test-helpers

Python
7
star
58

convey

Python
6
star
59

disqus-api-demos

Python
6
star
60

docker-pgqd

pgqd (PgQ Ticker Daemon) on Docker
Python
5
star
61

standup-helper

Disqus' standup bot + dashboard.
JavaScript
4
star
62

phab-trello

Phabricator-to-Trello Webhook
JavaScript
4
star
63

bokbok

JavaScript
4
star
64

imperium-python

Impermium API bindings for Python
Python
4
star
65

grunt-kssgen

KSS styleguide generator for grunt. - Alternative to grunt-kss since it is dead
JavaScript
4
star
66

diamond-collectors

Python
3
star
67

nginx-old

Nginx (PPA packaging)
C
2
star
68

nose-unittest

Python
2
star
69

datasketches-hive

Java
2
star
70

kazoo-eventlet-handler

Kazoo handler for usage in eventlet greenthreaded environments.
Python
2
star
71

smartrev

A "smart" file versioner for production environments which takes inter-file dependencies into account automatically.
2
star
72

trello-phab

Parse phab-trello webhook attachments
JavaScript
1
star
73

docker-heka

heka in a docker
1
star
74

Hive-JSON-Serde-tmp

Java
1
star
75

nginx

Disqus Nginx Build
C
1
star
76

facebook-sdk

Mirror of facebook-sdk
Python
1
star
77

dataweek2013

Scala
1
star
78

disqus-slack

post Disqus comments to a Slack channel or PM with /disqus <comment url>
JavaScript
1
star
79

kafka-python

mirror of original dpkp/kafka-python
Python
1
star