示例#1
0
func (s *Scenario) Run() {
	s.log = swarmlog.NewLogger("swarm.scenario")
	s.log.Println("Starting the scenario...")

	// Verify configuration values are valid
	if s.Consumers < 1 {
		s.log.Fatalln("Number of consumers must be 1 or more.")
		return
	}

	// If no creation rate is specified, then make it so all consumers
	// are generated at once.
	if s.CreationRate == nil {
		s.CreationRate = &Rate{Count: s.Consumers, Period: 1}
	}

	if s.Consumers < s.CreationRate.Count {
		s.log.Fatalln("Number of consumers must be greater than or equal to " +
			"number defined in creation rate.")
		return
	}

	// Start results collection
	s.Results = NewResults()

	// Start consumer generation
	go s.generateConsumers()

	go s.monitorConsumers()

	// Block until all consumers have finished
	<-s.consumersFinished

	s.Stop()
}
示例#2
0
func NewResults() *Results {
	results := &Results{
		resultsChan: make(chan *Result, 1024),
		stopChan:    make(chan bool),
		log:         swarmlog.NewLogger("swarm.results"),
	}

	go results.collect()

	return results
}
示例#3
0
func (s *SampleTask) Setup(consumer *swarm.Consumer) {
	s.log = swarmlog.NewLogger("sample-task")
	s.log.Println("Doing setup...")
	s.client = http.NewClient(consumer)
}
示例#4
0
func NewSampleTask(id int) *SampleTask {
	return &SampleTask{log: swarmlog.NewLogger("SampleTask " + strconv.Itoa(id))}
}
示例#5
0
func (a *SampleAggregateTask) Setup(consumer *swarm.Consumer) {
	a.log = swarmlog.NewLogger("SampleAggregateTask")
}