Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 2.89 KB

README.md

File metadata and controls

87 lines (63 loc) · 2.89 KB

quoracle-go

build Go Reference

A Golang port of mwhittaker/quoracle. For more information check the original paper Read-Write Quorum Systems Made Practical - Michael Whittaker, Aleksey Charapko, Joseph M. Hellerstein, Heidi Howard, Ion Stoica.

Requirements

This projects depends on lanl/clp to solve the linear optimization problems. lanl/clp relies on clp, which needs to be installed on your machine using the following instructions.

Get optimal strategy metrics

You can use quoracle-go to return the load, the capacity, the network load, and the latency of a strategy:

package main

import "fmt"

func main() {
	a, b, c, d :=
		NewNodeWithCapacityAndLatency("a", 2, 1, 1),
		NewNodeWithCapacityAndLatency("b", 2, 1, 2),
		NewNodeWithCapacityAndLatency("c", 2, 1, 3),
		NewNodeWithCapacityAndLatency("d", 2, 1, 4)

	// Read quorum (a*b) + (c*d)
	qs := NewQuorumSystemWithReads((a.Multiply(b)).Add(c.Multiply(d)))

	// Load optimized strategy with read_fraction 100%
	strategyOptions := StrategyOptions{
		Optimize: Load,
		ReadFraction: QuorumDistribution{
			values: DistributionValues{1: 1}},
	}

	load, _ := qs.Load(strategyOptions)
	capacity, _ := qs.Capacity(strategyOptions)
	networkLoad, _ := qs.NetworkLoad(strategyOptions)
	latency, _ := qs.Latency(strategyOptions)

	fmt.Println(fmt.Sprintf("Load: %f | Capacity: %f | Network load: %f | Latency: %f",
		load, capacity, networkLoad, latency)))
}

Optimized strategy search

The library provides a way to search for the optimal strategy. Below the example:

package main

import "fmt"

func main() {
	a, b, c, d :=
		NewNodeWithCapacityAndLatency("a", 2, 1, 1),
		NewNodeWithCapacityAndLatency("b", 2, 1, 2),
		NewNodeWithCapacityAndLatency("c", 2, 1, 3),
		NewNodeWithCapacityAndLatency("d", 2, 1, 4)

	so := SearchOptions{
		Optimize:     Load,
		ReadFraction: QuorumDistribution{DistributionValues{0.5: 1.0}},
	}

	sr, err := Search(so, a, b, c, d)

	if err != nil {
		fmt.Println(err.Error())
	}

	fmt.Println(sr.Strategy.GetReadQuorum())
	fmt.Println(sr.Strategy.GetWriteQuorum())
}

References