def receiveMsg_BenchmarkComplete(self, msg, sender): logger.info("Benchmark is complete.") logger.info("Bulk adding request metrics to metrics store.") self.metrics_store.bulk_add(msg.metrics) self.send(self.main_driver, thespian.actors.ActorExitRequest()) self.main_driver = None self.send(self.mechanic, mechanic.OnBenchmarkStop())
def receiveMessage(self, msg, sender): try: logger.debug( "BenchmarkActor#receiveMessage(msg = [%s] sender = [%s])" % (str(type(msg)), str(sender))) if isinstance(msg, Setup): self.start_sender = sender self.setup(msg) elif isinstance(msg, mechanic.EngineStarted): logger.info("Mechanic has started engine successfully.") self.metrics_store.meta_info = msg.system_meta_info cluster = msg.cluster_meta_info self.race.cluster = cluster console.info( "Racing on track [%s], challenge [%s] and car %s\n" % (self.race.track_name, self.race.challenge_name, self.race.car)) # start running we assume that each race has at least one lap self.run() elif isinstance(msg, driver.TaskFinished): logger.info("Task has finished.") logger.info("Bulk adding request metrics to metrics store.") self.metrics_store.bulk_add(msg.metrics) # We choose *NOT* to reset our own metrics store's timer as this one is only used to collect complete metrics records from # other stores (used by driver and mechanic). Hence there is no need to reset the timer in our own metrics store. self.send( self.mechanic, mechanic.ResetRelativeTime(msg.next_task_scheduled_in)) elif isinstance(msg, actor.BenchmarkCancelled): self.cancelled = True # even notify the start sender if it is the originator. The reason is that we call #ask() which waits for a reply. # We also need to ask in order to avoid races between this notification and the following ActorExitRequest. self.send(self.start_sender, msg) elif isinstance(msg, actor.BenchmarkFailure): logger.info( "Received a benchmark failure from [%s] and will forward it now." % sender) self.error = True self.send(self.start_sender, msg) elif isinstance(msg, driver.BenchmarkComplete): logger.info("Benchmark is complete.") logger.info("Bulk adding request metrics to metrics store.") self.metrics_store.bulk_add(msg.metrics) self.send(self.main_driver, thespian.actors.ActorExitRequest()) self.main_driver = None self.send(self.mechanic, mechanic.OnBenchmarkStop()) elif isinstance(msg, mechanic.BenchmarkStopped): logger.info("Bulk adding system metrics to metrics store.") self.metrics_store.bulk_add(msg.system_metrics) logger.info("Flushing metrics data...") self.metrics_store.flush() logger.info("Flushing done") self.lap_counter.after_lap() if self.lap_counter.has_more_laps(): self.run() else: self.teardown() elif isinstance(msg, mechanic.EngineStopped): logger.info("Mechanic has stopped engine successfully.") logger.info("Bulk adding system metrics to metrics store.") self.metrics_store.bulk_add(msg.system_metrics) self.metrics_store.flush() if not self.cancelled and not self.error: final_results = reporter.calculate_results( self.metrics_store, self.race) self.race.add_final_results(final_results) reporter.summarize(self.race, self.cfg) self.race_store.store_race(self.race) else: logger.info( "Suppressing output of summary report. Cancelled = [%r], Error = [%r]." % (self.cancelled, self.error)) self.metrics_store.close() self.send(self.start_sender, Success()) elif isinstance(msg, thespian.actors.ActorExitRequest): if self.mechanic: self.send(self.mechanic, msg) self.mechanic = None if self.main_driver: self.send(self.main_driver, msg) self.main_driver = None else: logger.info( "BenchmarkActor received unknown message [%s] (ignoring)." % (str(msg))) except BaseException as e: self.error = True logger.exception( "BenchmarkActor encountered a fatal exception. Shutting down.") self.send(self.start_sender, actor.BenchmarkFailure("Could not execute benchmark", e))