protected void Page_Load(object sender, EventArgs e) { this.AzureTableDataSource.TypeName = typeof(TestRunEntityTableContext).FullName; this.AzureTableDataSource.DataObjectTypeName = typeof(TestRunTableEntity).FullName; this.AzureTableDataSource.SelectMethod = "GetTestRuns"; this.AzureTableDataSource.ObjectCreating += (s, p) => { var storageAccountName = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingStorageAccount]; var storageAccountKey = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingStorageAccountKey]; var testRunsTableName = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingTestRunsTableName]; var creds = new StorageCredentialsAccountAndKey(storageAccountName, storageAccountKey); var storageAccount = new CloudStorageAccount(creds, true); var tableClient = storageAccount.CreateCloudTableClient(); var testRunTable = new TestRunEntityTableContext(tableClient.BaseUri.ToString(), tableClient.Credentials); testRunTable.TableName = testRunsTableName; p.ObjectInstance = testRunTable; }; this.AzureTableDataSource.Select(); this.AzureTableDataSource.DataBind(); }
/// <summary> /// Receives a notification when a new inter-role communication event occurs. /// </summary> public override void OnNext(TestRunStartEvent msg) { var numInstances = RoleEnvironment.CurrentRoleInstance.Role.Instances.Count - 1; var topicBaseCommunicator = this.interRoleCommunicator as InterRoleCommunicationExtension; if (topicBaseCommunicator != null) { topicBaseCommunicator.Settings.EnableAsyncPublish = msg.EnableAsyncPublish; topicBaseCommunicator.Settings.EnableAsyncDispatch = msg.EnableAsyncDispatch; } if (msg.RequireTopicCleanup) { // Delete the IRC topic first so that instances will have enough time to recreate senders and receivers. var serviceBusSettings = ConfigurationManager.GetSection(ServiceBusConfigurationSettings.SectionName) as ServiceBusConfigurationSettings; var pubsubType = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingPubSubType]; if (pubsubType.Equals(CommonConsts.ConfigSettingPubSubTypeValueTopic)) { var topicEndpoint = serviceBusSettings.Endpoints.Get(CommonConsts.TopicServiceBusEndpointName); var credentials = TokenProvider.CreateSharedSecretTokenProvider(topicEndpoint.IssuerName, topicEndpoint.IssuerSecret); var address = ServiceBusEnvironment.CreateServiceUri("sb", topicEndpoint.ServiceNamespace, String.Empty); var nsManager = new NamespaceManager(address, credentials); if (nsManager.GetTopics().Where(t => String.Compare(t.Path, topicEndpoint.TopicName, true) == 0).Count() > 0) { nsManager.DeleteTopic(topicEndpoint.TopicName); } } } if (msg.PurgeTraceLogTable) { // Purge WADLogsTable. PurgeTraceLogTable(); } // Tell ACK subscriber how many messages it should expect to receive and reset the ACK counter. this.ackSubscriber.SetExpectedAckCount(msg.MessageCount * numInstances); this.ackSubscriber.ResetAckCounter(); var testRun = new TestRunTableEntity() { TestRunID = msg.TestRunID, MessageCount = msg.MessageCount, MessageSize = msg.MessageSize, InstanceCount = numInstances, StartDateTime = DateTime.UtcNow, EndDateTime = new DateTime(1900, 1, 1) }; var testRunsTable = new TestRunEntityTableContext(this.tableClient.BaseUri.ToString(), this.tableClient.Credentials); testRunsTable.TableName = this.testRunsTableName; try { testRunsTable.AddTestRun(testRun); } catch (DataServiceRequestException ex) { if (ex.IsEntityAlreadyExists()) { testRunsTable.UpdateTestRun(testRun); } } using (TraceManager.WorkerRoleComponent.TraceScope("Publishing IRC events", msg.TestRunID, msg.MessageCount, msg.MessageSize)) { for (int i = 1; i <= msg.MessageCount; i++) { DemoPayload payload = new DemoPayload(msg.TestRunID, i, numInstances, DateTime.UtcNow); // Create a data portion of the payload equal to the message size specified in the test run settings. payload.Data = new byte[msg.MessageSize]; (new Random()).NextBytes(payload.Data); InterRoleCommunicationEvent ircEvent = new InterRoleCommunicationEvent(payload); // Update publish time so that it accurately reflects the current time. payload.PublishTickCount = HighResolutionTimer.CurrentTickCount; payload.PublishTime = DateTime.UtcNow; // Publish the IRC event. this.interRoleCommunicator.Publish(ircEvent); } } }
/// <summary> /// Filter the Results Table and generate stats for a particular test RUN /// </summary> /// <param name="testRunID"></param> /// <returns></returns> private void GenerateTestRunStats(Guid testRunID) { DateTime testRunFinished = DateTime.UtcNow; long minUnicastLatency = 0, maxUnicastLatency = 0, minMulticastLatency = 0, maxMulticastLatency = 0; double avgUnicastLatency = 0, avgMulticastLatency = 0; using (TraceManager.WorkerRoleComponent.TraceScope("Generating stats for test run: ", testRunID)) { var resultTable = new TestResultEntityTableContext(this.tableClient.BaseUri.ToString(), this.tableClient.Credentials); resultTable.TableName = this.tableName; var testRunTable = new TestRunEntityTableContext(this.tableClient.BaseUri.ToString(), this.tableClient.Credentials); testRunTable.TableName = ConfigurationManager.AppSettings[CommonConsts.ConfigSettingTestRunsTableName]; try { var testResults = from r in resultTable.DemoTestResults where r.PartitionKey == testRunID.ToString("N") select r; if (testResults != null) { var tr = testResults.ToList(); if (tr != null && tr.Count > 0) { minUnicastLatency = tr.Min(f => f.UnicastResponseTime); maxUnicastLatency = tr.Max(f => f.UnicastResponseTime); avgUnicastLatency = tr.Average(f => f.UnicastResponseTime); minMulticastLatency = tr.Min(f => f.MulticastResponseTime); maxMulticastLatency = tr.Max(f => f.MulticastResponseTime); avgMulticastLatency = tr.Average(f => f.MulticastResponseTime); } } var testRun = (from r in testRunTable.GetTestRuns() where r.PartitionKey == testRunID.ToString("N") select r).FirstOrDefault(); if (testRun != null) { testRun.EndDateTime = testRunFinished; testRun.AvgAckLatency = avgUnicastLatency; testRun.AvgReqLatency = avgMulticastLatency; // Number of published messages (N1) // Number of subscribers (S) // Number of messages recevied by each subscriber (N2) // Number of ACKs published by each subscriber (N3) // Number of ACKs receieved by publisher (N4) // Formula for throughput (msg/sec) calculation: (N1 + (N2 * S) + (N3 * S) + (N4 * S)) / Duration (seconds) testRun.Throughput = Convert.ToDouble(testRun.MessageCount + (testRun.MessageCount * testRun.InstanceCount) * 3) / (testRun.EndDateTime - testRun.StartDateTime).TotalSeconds; // Update test run stats in the Windows Azure table. testRunTable.UpdateTestRun(testRun); TestRunFinishEvent finishEvent = new TestRunFinishEvent() { TestRunID = testRunID, Duration = (testRun.EndDateTime - testRun.StartDateTime), Throughput = testRun.Throughput, MinUnicastLatency = minUnicastLatency, AvgUnicastLatency = avgUnicastLatency, MaxUnicastLatency = maxUnicastLatency, MinMulticastLatency = minMulticastLatency, AvgMulticastLatency = avgMulticastLatency, MaxMulticastLatency = maxMulticastLatency }; // Determine the role which will receive the TestRunFinishEvent event. var targetRole = RoleEnvironment.Roles.Where(r => { return(r.Value != RoleEnvironment.CurrentRoleInstance.Role); }).Select(i => i.Value).FirstOrDefault(); if (targetRole != null) { TraceManager.WorkerRoleComponent.TraceInfo("Sending TestRunFinishEvent for test run {0} to role {1}", testRunID, targetRole.Name); // Send the TestRunFinishEvent instance back to the web role for visualization. this.interRoleCommunicator.Publish(new InterRoleCommunicationEvent(finishEvent, roleName: targetRole.Name)); } } } catch (Exception ex) { TraceManager.WorkerRoleComponent.TraceError(ex); } } }