Git Product home page Git Product logo

montage's Introduction

Montage: a riak resolution proxy

Even Rocky had a montage...

Install

Built and tested with ghc 7.4.1

Install the non-hackage dependencies:

git clone [email protected]:wmoss/StatsWeb.git
cd StatsWeb && cabal install

git clone [email protected]:bumptech/riak-haskell-client.git
cd riak-haskell-client && cabal install

From montage/ execute:

cabal install

We recommend using a sandbox, hsenv is particularly good.

Configuration =======

The montage proxy is port configurable (here given the Config handle set to 7078), with riak running on 8087:

import Network.Riak (defaultClient, connect, disconnect, Client(port), Connection)
import Data.Conduit.Pool (Pool, createPool)

import Network.Riak.Montage

main :: IO ()
main = do
    mainPool <- createPool
    (connect $ defaultClient {port = "8087"})
    disconnect
    1 -- stripes
    10 -- timeout
    300 -- max connections

let cfg' = cfg { proxyPort = 7078 }

runDaemon (cfg' :: Config ResObject) mainPool
ResObject is a concrete datatype you define. For Montage to work with this datatype, you must define:
  1. translations from bytestring -> datatype, datatype -> bytestring,
  2. methods for resolving siblings,
  3. and how to obtain a bytestring key from values in the datatype

See examples/ for a definition of ResObject and how to implement (1), (2), and (3).

You can also set the mainPool argument to be a datatype with more than one pool, in case particular buckets have such variable resolution times that you want to isolate your bucket fetches:

data Pools = Pools {
    poolA :: Pool Connection
  , poolB :: Pool Connection
}

instance Poolable Pools where
    chooser pools "bucketA" = poolA pools
    chooser pools "bucketB" = poolB pools
    chooser pools "bucketC" = poolC pools

For a single pool, like mainPool, you're also required to define its datatype as an instance of Poolable, such that the bucket doesn't matter:

instance Poolable (Pool Connection) where
    chooser pool _ = pool

You can also a set the cfg field 'logger' to a logging function that fits the type signature:

logger :: B.Bytestring -> Maybe Double -> Value -> IO ()
logger errorType duration val = -- your defintion

where errorType is filled in by the Montage exception handler with the type of exception (useful as a prefix), duration is a timestamp Montage may provide (depending on where the error occurs), and val is JSON that Montage constructs with details about the error.

Since Montage provides these values, your logger would simply format the arguments and broadcasts them to a location of your choice. The default logger simply concatenates the arguments and broadcasts to stderr.

Examples ======= To setup the examples, first download hprotoc:

cabal install hprotoc

Then execute:

cd examples && hprotoc user.proto

Then:

cd examples && runhaskell basic_proxy.hs

For client examples to run against the basic_proxy, see github.com/bumptech/montage-haskell-client/examples

More

See the haddock documentation for type-signatures, descriptions, and source of client functions.

montage's People

Contributors

wmoss avatar edahlgren 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.