Skip to content

Commit

Permalink
added strategy graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
kbala444 committed Aug 14, 2015
1 parent b08a6c0 commit 6b3f826
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 79 deletions.
16 changes: 16 additions & 0 deletions data/grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ def fsize_time(self):
g = sns.lmplot("size", "time", data=df, scatter=True, col='bandwidth')
g.set_axis_labels("file size (Kb)", "mean file time (s)")

@is_graph('graph of strategy vs files times for manual links')
def strategy_times(self):
# split on workload, boxplot based on strategy and duration stats,
df_dict = {'time': [], 'workload': [], 'strategy': []}

self.cur.execute('SELECT runid, workload, duration, strategy FROM runs WHERE manual=1')
rows = self.cur.fetchall()
for rid, wl, d, strat in rows:
#df['id'].append(rid)
df_dict['workload'].append(wl)
df_dict['strategy'].append(strat)
df_dict['time'].append(d)

df = pd.DataFrame.from_dict(df_dict)
g = sns.factorplot(x='strategy', y='time', data=df, col='workload', kind='box')

# saves/shows graphs if specified in config and closes connection
def finish(self):
if self.config.getboolean('general', 'save'):
Expand Down
20 changes: 11 additions & 9 deletions data/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ CREATE TABLE "block_times" (
"runid" INTEGER,
"peerid" TEXT
);
CREATE TABLE "file_times" (
"timestamp" INTEGER,
"time" INTEGER,
"runid" INTEGER,
"peerid" TEXT,
"size" INTEGER
);
CREATE TABLE runs (
"runid" INTEGER,
"node_count" INTEGER,
Expand All @@ -14,12 +21,7 @@ CREATE TABLE runs (
"latency" REAL,
"bandwidth" REAL,
"duration" INTEGER,
"dup_blocks" INTEGER
, "workload" TEXT);
CREATE TABLE "file_times" (
"timestamp" INTEGER,
"time" INTEGER,
"runid" INTEGER,
"peerid" TEXT,
"size" INTEGER
);
"dup_blocks" INTEGER,
"workload" TEXT,
"strategy" TEXT
, "manual" INTEGER);
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ func createTestNetwork() (mocknet.Mocknet, []bs.Instance) {
// Adds random identities to the mocknet, creates bitswap instances for them, and links + connects them
func genInstances(n int, mn *mocknet.Mocknet, snet *tn.Network) []bs.Instance {
// Validate strategy
fmt.Println(decision.Strats)
fmt.Println(config["strategy"])
strat, ok := decision.Strats[config["strategy"]]
if !ok{
log.Fatal("Invalid strategy", config["strategy"])
Expand Down
89 changes: 21 additions & 68 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,23 @@ import (
"bytes"
"os"
"sync"
//"log"
"database/sql"
"errors"
"fmt"
bs "github.com/ipfs/go-ipfs/exchange/bitswap"
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
"github.com/ipfs/go-ipfs/p2p/peer"
_ "github.com/heems/bssim/Godeps/_workspace/src/github.com/mattn/go-sqlite3"
prom "github.com/heems/bssim/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
"strconv"
"time"
)

var (
labels = []string{"latency", "bandwidth", "block_size"}
// NewSummaryVec(opts, ["filename", "pid", "latency", "bandwidth"]
fileTimes = prom.NewHistogramVec(prom.HistogramOpts{
Name: "file_times_ms",
Help: "Time for peer to get a file.",
Buckets: prom.LinearBuckets(1, .25, 12),
}, labels)

blockTimes = prom.NewHistogramVec(prom.HistogramOpts{
Name: "block_times_ms",
Help: "Time for peer to get a block.",
Buckets: prom.ExponentialBuckets(0.005, 10, 10),
//Buckets: prom.LinearBuckets(0, .05, 100),
}, labels)

dupBlocks = prom.NewGaugeVec(prom.GaugeOpts{
Name: "dup_blocks_count",
Help: "Count of total duplicate blocks received.",
}, labels)

currLables prom.Labels
)

func init() {
prom.MustRegister(fileTimes)
prom.MustRegister(blockTimes)
prom.MustRegister(dupBlocks)
}

type Recorder struct {
createdAt time.Time
currID int
times map[int]time.Time
rid int
currLables []string
prom *PromHandler
db *sql.DB
// main transaction
tx *sql.Tx
Expand Down Expand Up @@ -114,13 +82,20 @@ func (r *Recorder) Kill() {
func (r *Recorder) Commit(workload string) {
duration := time.Since(r.createdAt)
dup := DupBlocksReceived(peers)

var ml int
if config["manual_links"] == "true"{
ml = 1
} else {
ml = 0
}

// oh god
_, err := r.tx.Exec(`INSERT INTO runs(runid, node_count, visibility_delay, query_delay,
block_size, deadline, bandwidth, latency, duration, dup_blocks, workload) values(?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, r.rid, config["node_count"], config["visibility_delay"],
block_size, deadline, bandwidth, latency, duration, dup_blocks, workload, strategy, manual) values(?,
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, r.rid, config["node_count"], config["visibility_delay"],
config["query_delay"], config["block_size"], config["deadline"], config["bandwidth"],
config["latency"], duration, dup, workload)
config["latency"], duration, dup, workload, config["strategy"], ml)
check(err)

err = r.tx.Commit()
Expand Down Expand Up @@ -152,17 +127,18 @@ func (r *Recorder) EndFileTime(id int, pid string, filename string) {
elapsed := time.Since(r.times[id])
t := elapsed.Seconds()
delete(r.times, id)

fileTimes.With(getLabels()).Observe(elapsed.Seconds() * 1000)


if r.prom != nil{
r.prom.Observe(fileTimes, elapsed)
}

// how to best get file size without opening it?
bs, err := strconv.Atoi(config["block_size"])
check(err)
// multiply block size with # of blocks that make file to get file size...
fsize := bs * len(files[filename])

r.stmnts["file_times"].Exec(tstamp, t, r.rid, pid, fsize)
updateDupBlocks()
}

// Ends timer with given id and records data for peer with given pretty id
Expand All @@ -171,11 +147,12 @@ func (r *Recorder) EndBlockTime(id int, pid string) {
elapsed := time.Since(r.times[id])
t := elapsed.Seconds() * 1000
delete(r.times, id)

blockTimes.With(getLabels()).Observe(elapsed.Seconds() * 1000)


if r.prom != nil{
r.prom.Observe(blockTimes, elapsed)
}

r.stmnts["block_times"].Exec(tstamp, t, r.rid, pid)
//updateDupBlocks()
}

// Returns mean block request fulfillment time of an instance in ms
Expand Down Expand Up @@ -312,30 +289,6 @@ func GetUploadTotal(peers []bs.Instance, source int, verbose bool, writepath str
return
}

func getLabels() prom.Labels {
if currLables != nil {
return currLables
}

currLables := make(map[string]string, 0)
for _, label := range labels {
currLables[label] = config[label]
}
return currLables
}

func updateDupBlocks() {
var blocks int
for _, p := range peers {
pstat, err := p.Exchange.Stat()
if err != nil {
fmt.Println("Unable to get stats from peer ", p.Peer)
}
blocks += pstat.BlocksReceived
}
dupBlocks.With(getLabels()).Set(float64(blocks))
}

func (r *Recorder) ReportStats() {
fmt.Println("\n\n==============STATS=============\n\n")
for num, peer := range peers {
Expand Down

0 comments on commit 6b3f826

Please sign in to comment.