Code Monkey home page Code Monkey logo

vulcan's Introduction

Build Status Build Status Coverage Status

Status

Don't use it in production, early adopters and hackers are welcome

Proxy for HTTP services

Vulcan is a proxy built for APi's specific needs that are usually different from website's needs. It is a proxy that you program in JavaScript.

function handle(request){
    return {upstreams: ["http://localhost:5000", "http://localhost:5001"]}
}

How slow can your proxy be?

One wants proxies to be fast, but in case of services proxy is rarely a bottleneck, whereas DB and filesystem are. Vulcan supports rate limiting using memory, Cassandra or Redis backends, so your service can introduce proper account-specific rates and expectations right from the start.

function handle(request){
    return {
        failover: true,
        upstreams: ["http://localhost:5000", "http://localhost:5001"],
        rates: {request.ip: ["10 requests/second", "1000 KB/second"]}
    }
}

Discover FTW!

Storing upstreams in files is ok up to a certain extent. On the other hand, keeping upstreams in a discovery service simplifies deployment and configuration management. Vulcan supports Etcd or Zookeeper:

function handle(request){
    return {
        upstreams: discover("/upstreams"),
        rates: {request.ip: ["10 requests/second", "1000 KB/second"]}
    }
}

Caching and Auth

Auth is hard and you don't want every endpoint to implement auth. It's better to implement auth endpoint once, and make proxy deal with it. As a bonus you can cache results using memory, Redis or Cassandra, reducing load on the databases holding account creds.

function handle(request){
    response = get(discover("/auth-endpoints"), {auth: request.auth}, {cache: true})
    if(!response.code == 200) {
        return response
    }
    return {
        upstreams: discover("/upstreams"),
        rates: {request.ip: ["10 requests/second", "1000 KB/second"]}
    }
}

And many more advanced features you'd need when writing APIs, like Metrics and Failure detection. Read on!

Development setup

Mailing list: https://groups.google.com/forum/#!forum/vulcan-proxy

Install go

(http://golang.org/doc/install)

Get vulcan and install deps

# set your GOPATH to something reasonable.
export GOPATH=~/projects/vulcan
cd $GOPATH
go get github.com/mailgun/vulcan

make -C ./src/github.com/mailgun/vulcan deps
cd ./src/github.com/mailgun/vulcan

Run in devmode

make run

Cassandra

Cassandra-based throttling is a generally good idea, as it provides reliable distributed counters that can be shared between multiple instances of vulcan. Vulcan provides auto garbage collection and cleanup of the counters.

Tested on versions >= 1.2.5

Usage

vulcan \
       -h=0.0.0.0\                  # interface to bind to
       -p=4000\                     # port to listen on
       -c=http://localhost:5000 \   # control server url#1
       -c=http://localhost:5001 \   # control server url#2, for redundancy
       -stderrthreshold=INFO \      # log info, from glog
       -logtostderr=true \          # log to stderror
       -logcleanup=24h \            # clean up logs every 24 hours
       -log_dir=/var/log/           # keep log files in this folder
       -pid=/var/run/vulcan.pid     # create pid file
       -lb=roundrobin \             # use round robin load balancer
       -b=cassandra \               # use cassandra for throttling
       -cscleanup=true \            # cleanup old counters
       -cscleanuptime=19:05 \       # cleanup counters 19:05 UTC every day
       -csnode=localhost  \         # cassandra node, can be multiple
       -cskeyspace=vulcan_dev       # cassandra keyspace

Development

To run server in development mode:

make run

To run tests

make test

To run tests with coverage:

make coverage

To cleanup temp folders

make clean

Status

Initial development done, loadtesting at the moment and fixing quirks.

vulcan's People

Contributors

dreid avatar klizhentas avatar obukhov-sergey avatar pquerna avatar r0mant avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.