Skip to content

Commit

Permalink
Linear
Browse files Browse the repository at this point in the history
  • Loading branch information
salemmohammed committed Jun 1, 2021
1 parent bb2a005 commit 0e12fde
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 129 deletions.
Binary file modified .DS_Store
Binary file not shown.
12 changes: 3 additions & 9 deletions benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// DB is general interface implemented by client to call client library
type DB interface {
Init() error
Read(key int) (int, error)
Write(key int, value []byte,Globalcounter int) error
Stop() error
}
Expand Down Expand Up @@ -147,18 +146,18 @@ func (b *Benchmark) Run() {
keys := make(chan int, b.Concurrency)
latencies := make(chan time.Duration, 1000)

globalCouner := make(chan int, 10)
globalCouner := make(chan int, 1000)

defer close(latencies)
go b.collect(latencies)

// number of threads or concurrency
for i := 0; i < b.Concurrency; i++ {
// this b is object calls worker function
go func() {
b.worker(keys, latencies,globalCouner)
}()
}

b.db.Init()
b.startTime = time.Now()
if b.T > 0 {
Expand Down Expand Up @@ -189,6 +188,7 @@ func (b *Benchmark) Run() {
b.db.Stop()
close(keys)
close(globalCouner)
log.Debugf("--------------------done -------------2")
stat := Statistic(b.latency)
log.Infof("Concurrency = %d", b.Concurrency)
log.Infof("Write Ratio = %f", b.W)
Expand Down Expand Up @@ -257,18 +257,12 @@ func (b *Benchmark) worker(keys <-chan int, result chan<- time.Duration, globalC
for k := range keys {
op := new(operation)
if rand.Float64() < b.W {
//v = rand.Int()
//log.Debugf("value %v", data)
s = time.Now()

//counter++
//slog.Debugf("globalCouner = %v", <- globalCouner)
err = b.db.Write(k, data,<- globalCouner)
e = time.Now()
op.input = data
} else {
s = time.Now()
//v, err = b.db.Read(k)
e = time.Now()
op.output = data
}
Expand Down
18 changes: 9 additions & 9 deletions bin/config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"address": {
"1.1": "tcp://18.221.231.103:1735",
"1.2": "tcp://3.135.241.193:1736",
"1.3": "tcp://3.15.147.83:1737",
"1.4": "tcp://3.15.239.10:1738"
"1.1": "tcp://127.0.0.1:1735",
"1.2": "tcp://127.0.0.1:1736",
"1.3": "tcp://127.0.0.1:1737",
"1.4": "tcp://127.0.0.1:1738"
},
"http_address": {
"1.1": "http://18.221.231.103:8080",
"1.2": "http://3.135.241.193:8081",
"1.3": "http://3.15.147.83:8082",
"1.4": "http://3.15.239.10:8083"
"1.1": "http://127.0.0.1:8080",
"1.2": "http://127.0.0.1:8081",
"1.3": "http://127.0.0.1:8082",
"1.4": "http://127.0.0.1:8083"
},
"policy": "majority",
"threshold": 3,
Expand All @@ -23,7 +23,7 @@
"K": 1000,
"W": 1,
"Throttle": 0,
"Concurrency": 1,
"Concurrency": 4,
"Distribution": "uniform",
"LinearizabilityCheck": false,
"Conflicts": 0,
Expand Down
15 changes: 6 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ import (
)
var List []ID
var rr int = 0
//type SafeCounter struct {
// mu sync.Mutex
// v map[string]int
//}
// Client interface provides get and put for key value store

type Client interface {
GetMUL(Key) ([]Value, []map[string]string)
PutMUL(Key, Value) []error
PutMUL(Key, Value,int) error
Get(Key) (Value, error)
Put(Key, Value,int) error
Next([]ID) ID
Expand Down Expand Up @@ -140,15 +136,16 @@ func (c *HTTPClient) GetMUL(key Key) ([]Value, []map[string]string) {

// Put puts new key value pair and return previous value (use REST)
// Default implementation of Client interface
func (c *HTTPClient) PutMUL(key Key, value Value) []error {
func (c *HTTPClient) PutMUL(key Key, value Value,Globalcounter int) error {
log.Debugf("<----------------PutMUL---------------->")
i := 0
log.Debugf("Put Function Globalcounter = %v", Globalcounter)
errs := make(chan error,len(c.HTTP))
for id := range c.HTTP {
//log.Debugf("id=%v",id)
go func(id ID) {
c.CID++
_, _, err := c.rest(id, key, value,c.CID,0)
_, _, err := c.rest(id, key, value,c.CID,Globalcounter)
if err != nil {
log.Error(err)
return
Expand All @@ -162,7 +159,7 @@ func (c *HTTPClient) PutMUL(key Key, value Value) []error {
errors = append(errors, <-errs)
}
//log.Debugf("errors %v ", errors)
return errors
return errors[0]
}

func (c *HTTPClient) GetURL(id ID, key Key) string {
Expand Down
14 changes: 2 additions & 12 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"encoding/binary"
"flag"
"fmt"
"github.com/salemmohammed/BigBFT"
"github.com/salemmohammed/BigBFT/log"

Expand All @@ -12,7 +12,6 @@ var id = flag.String("id", "", "node id this client connects to")
var algorithm = flag.String("algorithm", "consensus", "Client API type [paxos, chain]")
var load = flag.Bool("load", false, "Load K keys into DB")

// db implements BigBFT.DB interface for benchmarking
type db struct {
BigBFT.Client
}
Expand All @@ -25,22 +24,13 @@ func (d *db) Stop() error {
return nil
}

func (d *db) Read(k int) (int, error) {
key := BigBFT.Key(k)
v, err := d.Get(key)
if len(v) == 0 {
return 0, nil
}
x, _ := binary.Uvarint(v)
return int(x), err
}

func (d *db) Write(k int, v []byte, Globalcounter int) error {
key := BigBFT.Key(k)
//value := make([]byte, binary.MaxVarintLen64)
//binary.PutUvarint(value, uint64(v))
log.Debugf("write function global counter = %v", Globalcounter)
err := d.Put(key, v,Globalcounter)
fmt.Println("k = %v", k)
return err
}

Expand Down
Loading

0 comments on commit 0e12fde

Please sign in to comment.