Browse Source

write to file

pull/9/head
Jae Kwon 10 years ago
parent
commit
cdbc760cee
1 changed files with 28 additions and 1 deletions
  1. +28
    -1
      sim/bench_votes.go

+ 28
- 1
sim/bench_votes.go View File

@ -1,9 +1,11 @@
package main package main
import ( import (
"bufio"
"container/heap" "container/heap"
"fmt" "fmt"
"math/rand" "math/rand"
"os"
) )
const seed = 0 const seed = 0
@ -17,8 +19,27 @@ const sendQueueCapacity = 40 // Amount of messages to queue between peers.
const maxAllowableRank = 2 // After this, the data is considered waste. const maxAllowableRank = 2 // After this, the data is considered waste.
const tryUnsolicited = 0.1 // Chance of sending an unsolicited piece of data. const tryUnsolicited = 0.1 // Chance of sending an unsolicited piece of data.
var log *bufio.Writer
func init() { func init() {
rand.Seed(seed) rand.Seed(seed)
openFile()
}
//-----------------------------------------------------------------------------
func openFile() {
// open output file
fo, err := os.Create("output.txt")
if err != nil {
panic(err)
}
// make a write buffer
log = bufio.NewWriter(fo)
}
func logWrite(s string) {
log.Write([]byte(s))
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -286,8 +307,8 @@ func countFull(nodes []*Node) (fullCount int) {
type runStat struct { type runStat struct {
time int32 // time for all events to propagate time int32 // time for all events to propagate
fill float64 // avg % of pieces gotten fill float64 // avg % of pieces gotten
dups float64 // % of times that a received data was duplicate
succ float64 // % of times the sendQueue was not full succ float64 // % of times the sendQueue was not full
dups float64 // % of times that a received data was duplicate
} }
func (s runStat) String() string { func (s runStat) String() string {
@ -380,6 +401,8 @@ func main() {
rank: rank, rank: rank,
}) })
logWrite(fmt.Sprintf("[%v] t:%v s:%v -> n:%v p:%v r:%v\n", len(runStats), event.time, srcPeer.node.index, node.index, event.part, rank))
if rank > 1 { if rank > 1 {
// Already has this part, ignore this event. // Already has this part, ignore this event.
numReceives++ numReceives++
@ -400,9 +423,11 @@ func main() {
part: event.part, part: event.part,
}) })
if sent { if sent {
logWrite(fmt.Sprintf("p:%v WS\n", peer.node.index))
peer.setGiven(event.part) peer.setGiven(event.part)
numSendSuccess++ numSendSuccess++
} else { } else {
logWrite(fmt.Sprintf("p:%v WF\n", peer.node.index))
numSendFailure++ numSendFailure++
} }
} else { } else {
@ -415,9 +440,11 @@ func main() {
part: event.part, part: event.part,
}) })
if sent { if sent {
logWrite(fmt.Sprintf("p:%v TS\n", peer.node.index))
peer.setGiven(event.part) peer.setGiven(event.part)
// numSendSuccess++ // numSendSuccess++
} else { } else {
logWrite(fmt.Sprintf("p:%v TF\n", peer.node.index))
// numSendFailure++ // numSendFailure++
} }
} }


Loading…
Cancel
Save