Example #1
0
func PrintReport(client types.TestRepPoolClient, results []types.AuctionResult, representatives []string, duration time.Duration, rules types.AuctionRules) {
	roundsDistribution := map[int]int{}
	auctionedInstances := map[string]bool{}

	///
	fmt.Println("Rounds Distributions")
	for _, result := range results {
		roundsDistribution[result.NumRounds] += 1
		auctionedInstances[result.Instance.InstanceGuid] = true
	}

	for i := 1; i <= rules.MaxRounds; i++ {
		if roundsDistribution[i] > 0 {
			fmt.Printf("  %2d: %s\n", i, strings.Repeat("■", roundsDistribution[i]))
		}
	}

	///

	fmt.Println("Distribution")
	maxGuidLength := 0
	for _, guid := range representatives {
		if len(guid) > maxGuidLength {
			maxGuidLength = len(guid)
		}
	}
	guidFormat := fmt.Sprintf("%%%ds", maxGuidLength)

	numNew := 0
	for _, guid := range representatives {
		repString := fmt.Sprintf(guidFormat, guid)
		lossyRep, ok := client.(*lossyrep.LossyRep)
		if ok && lossyRep.FlakyReps[guid] {
			repString = fmt.Sprintf("%s"+guidFormat+"%s", redColor, repString, defaultStyle)
		}

		instanceString := ""
		instances := client.Instances(guid)

		availableColors := []string{"red", "cyan", "yellow", "gray", "plurple", "green"}
		colorLookup := map[string]string{"red": redColor, "green": greenColor, "cyan": cyanColor, "yellow": yellowColor, "gray": lightGrayColor, "plurple": plurpleColor}

		originalCounts := map[string]int{}
		newCounts := map[string]int{}
		for _, instance := range instances {
			key := "green"
			if _, ok := colorLookup[instance.AppGuid]; ok {
				key = instance.AppGuid
			}
			if auctionedInstances[instance.InstanceGuid] {
				newCounts[key] += 1
				numNew += 1
			} else {
				originalCounts[key] += 1
			}
		}
		for _, col := range availableColors {
			instanceString += strings.Repeat(colorLookup[col]+"○"+defaultStyle, originalCounts[col])
			instanceString += strings.Repeat(colorLookup[col]+"●"+defaultStyle, newCounts[col])
		}
		instanceString += strings.Repeat(grayColor+"○"+defaultStyle, client.TotalResources(guid)-len(instances))

		fmt.Printf("  %s: %s\n", repString, instanceString)
	}

	fmt.Printf("Finished %d Auctions among %d Representatives in %s\n", len(results), len(representatives), duration)
	if numNew < len(auctionedInstances) {
		expected := len(auctionedInstances)
		fmt.Printf("  %s!!!!MISSING INSTANCES!!!!  Expected %d, got %d (%.3f %% failure rate)%s", redColor, expected, numNew, float64(expected-numNew)/float64(expected), defaultStyle)
	}
	fmt.Printf("  MaxConcurrent: %d, MaxBiddingBool:%d, RepickEveryRound: %t, MaxRounds: %d\n", rules.MaxConcurrent, rules.MaxBiddingPool, rules.RepickEveryRound, rules.MaxRounds)
	if _, ok := client.(*lossyrep.LossyRep); ok {
		fmt.Printf("  Latency Range: %s < %s, Timeout: %s, Flakiness: %.2f\n", lossyrep.LatencyMin, lossyrep.LatencyMax, lossyrep.Timeout, lossyrep.Flakiness)
	}

	///

	fmt.Println("Times")
	minTime, maxTime, totalTime, meanTime := time.Hour, time.Duration(0), time.Duration(0), time.Duration(0)
	for _, result := range results {
		if result.Duration < minTime {
			minTime = result.Duration
		}
		if result.Duration > maxTime {
			maxTime = result.Duration
		}
		totalTime += result.Duration
		meanTime += result.Duration
	}

	meanTime = meanTime / time.Duration(len(results))
	fmt.Printf("  Min: %s | Max: %s | Total: %s | Mean: %s\n", minTime, maxTime, totalTime, meanTime)

	///

	fmt.Println("Rounds")
	minRounds, maxRounds, totalRounds, meanRounds := 100000000, 0, 0, float64(0)
	for _, result := range results {
		if result.NumRounds < minRounds {
			minRounds = result.NumRounds
		}
		if result.NumRounds > maxRounds {
			maxRounds = result.NumRounds
		}
		totalRounds += result.NumRounds
		meanRounds += float64(result.NumRounds)
	}

	meanRounds = meanRounds / float64(len(results))
	fmt.Printf("  Min: %d | Max: %d | Total: %d | Mean: %.2f\n", minRounds, maxRounds, totalRounds, meanRounds)

	///

	fmt.Println("Votes")
	minVotes, maxVotes, totalVotes, meanVotes := 100000000, 0, 0, float64(0)
	for _, result := range results {
		if result.NumVotes < minVotes {
			minVotes = result.NumVotes
		}
		if result.NumVotes > maxVotes {
			maxVotes = result.NumVotes
		}
		totalVotes += result.NumVotes
		meanVotes += float64(result.NumVotes)
	}

	meanVotes = meanVotes / float64(len(results))
	fmt.Printf("  Min: %d | Max: %d | Total: %d | Mean: %.2f\n", minVotes, maxVotes, totalVotes, meanVotes)

}
Example #2
0
)

var guids []string
var natsAddrs []string

var numReps int
var repResources int

var rules types.AuctionRules
var timeout time.Duration

var auctioneerMode string

// plumbing
var natsClient yagnats.NATSClient
var client types.TestRepPoolClient
var communicator types.AuctionCommunicator

func init() {
	flag.StringVar(&auctioneerMode, "auctioneerMode", "inprocess", "one of inprocess, remote")

	flag.IntVar(&(auctioneer.DefaultRules.MaxRounds), "maxRounds", auctioneer.DefaultRules.MaxRounds, "the maximum number of rounds per auction")
	flag.IntVar(&(auctioneer.DefaultRules.MaxBiddingPool), "maxBiddingPool", auctioneer.DefaultRules.MaxBiddingPool, "the maximum number of participants in the pool")
	flag.IntVar(&(auctioneer.DefaultRules.MaxConcurrent), "maxConcurrent", auctioneer.DefaultRules.MaxConcurrent, "the maximum number of concurrent auctions to run")
	flag.BoolVar(&(auctioneer.DefaultRules.RepickEveryRound), "repickEveryRound", auctioneer.DefaultRules.RepickEveryRound, "whether to repick every round")
}

func TestAuction(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Auction Suite")
}