Exemplo n.º 1
0
        /// <summary>
        /// Main program entry
        /// </summary>
        private static void Main()
        {
            MeasureThreadStartup();

            foreach (var threadCount in new[] { 2, 8, 64, 128, 512, 2048, })
            {
                var stopWatch = Stopwatch.StartNew();

                int count = new VegaTracingPerf
                {
                    numberOfThreads = threadCount,
                }.Run();

                stopWatch.Stop();
                Console.WriteLine(
                    "Total execution time: {0} ms, throughput: {1:F3} count/sec. Received: {2} Dropped: {3}\n",
                    stopWatch.ElapsedMilliseconds,
                    count * 1000.0 / stopWatch.ElapsedMilliseconds,
                    LogFileEventTracing.ReceivedTraceCount,
                    LogFileEventTracing.DroppedTraceCount);

                Thread.Sleep(1000 * 2);
            }

            LogFileEventTracing.Stop();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Measures the thread startup cost
        /// </summary>
        private static void MeasureThreadStartup()
        {
            var loggingDirectory = Path.Combine(Path.GetTempPath(), "TracePerfTest");

            LogFileEventTracing.Start(loggingDirectory);

            var stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < 100000; i++)
            {
                var thread = new Thread(() =>
                {
                    LogFileEventTracing.Trace($"Thread {i}");
                });

                thread.Start();
                thread.Join();
            }

            stopwatch.Stop();
            Console.WriteLine(
                "MeasureThreadStartup: {0} ms  Workingset: {1}",
                stopwatch.ElapsedMilliseconds,
                Process.GetCurrentProcess().WorkingSet64);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Setup trace log.
        /// </summary>
        /// <param name="logFileDirectory">the log file directory name.</param>
        public static void SetupTraceLog(string logFileDirectory)
        {
            if (string.IsNullOrWhiteSpace(logFileDirectory))
            {
                throw new ArgumentNullException(nameof(logFileDirectory));
            }

            LogFileEventTracing.Start(logFileDirectory);

            int index = 0;

            while (index < Trace.Listeners.Count)
            {
                var listener = Trace.Listeners[index] as LogFileTraceListener;
                if (listener != null)
                {
                    return;
                }

                index++;
            }

            Trace.Listeners.Add(new LogFileTraceListener());

            AppDomain.CurrentDomain.ProcessExit +=
                (sender, eventArgs) =>
            {
                LogFileEventTracing.Stop();
            };
        }
Exemplo n.º 4
0
        private static void AddAllEventSources()
        {
            // Ensure the event source is loaded
            Assembly.GetAssembly(typeof(Backend.RingMasterBackendCore))
            .GetType("Microsoft.Azure.Networking.Infrastructure.RingMaster.Backend.RingMasterEventSource")
            ?.GetProperty("Log")
            ?.GetValue(null);
            Assembly.GetAssembly(typeof(AbstractPersistedDataFactory))
            .GetType("Microsoft.Azure.Networking.Infrastructure.RingMaster.Persistence.PersistenceEventSource")
            ?.GetProperty("Log")
            ?.GetValue(null);
            Assembly.GetAssembly(typeof(WinFabPersistence.PersistedData))
            .GetType("Microsoft.Azure.Networking.Infrastructure.RingMaster.Persistence.ServiceFabric.ServiceFabricPersistenceEventSource")
            ?.GetProperty("Log")
            ?.GetValue(null);
            Assembly.GetAssembly(typeof(Transport.SecureTransport))
            .GetType("Microsoft.Azure.Networking.Infrastructure.RingMaster.Transport.SecureTransportEventSource")
            ?.GetProperty("Log")
            ?.GetValue(null);

            var level = EventLevel.Informational;

            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Fabric-RingMasterService", level, "RingMasterService");
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Backend-RingMasterEvents", level, "RingMasterBackendCore");
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Persistence", EventLevel.Warning, "Persistence");
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Persistence-ServiceFabric", level, "ServiceFabricPersistence");
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-SecureTransport", level, "SecureTransport");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Entry point
        /// </summary>
        public static void Main()
        {
            var            path        = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var            builder     = new ConfigurationBuilder().SetBasePath(Path.GetDirectoryName(path)).AddJsonFile("appSettings.json");
            IConfiguration appSettings = builder.Build();

            RingMasterApplicationHelper.AttachDebugger(int.Parse(appSettings["DebuggerAttachTimeout"]));

            LogFileEventTracing.Start(Path.Combine(appSettings["LogFolder"], "RingMasterWatchdog.LogPath"));

            AppDomain.CurrentDomain.ProcessExit +=
                (sender, eventArgs) =>
            {
                LogFileEventTracing.Stop();
            };

            using (FabricRuntime fabricRuntime = FabricRuntime.Create())
            {
                try
                {
                    var monitoringConfiguration = new MonitoringConfiguration(FabricRuntime.GetActivationContext());

                    IfxInstrumentation.Initialize(monitoringConfiguration.IfxSession, monitoringConfiguration.MdmAccount);

                    RingMasterWatchdogEventSource.Log.ConfigurationSettings(
                        monitoringConfiguration.Environment,
                        monitoringConfiguration.Tenant,
                        monitoringConfiguration.Role,
                        monitoringConfiguration.IfxSession,
                        monitoringConfiguration.MdmAccount);

                    LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Fabric-RingMasterWatchdog", EventLevel.Informational, "RingMasterWatchdog");
                    LogFileEventTracing.AddEventSource("Microsoft-ServiceFabric-Services", EventLevel.Informational, "ServiceFabricServices");
                    Trace.Listeners.Add(new LogFileTraceListener());

                    var metricsFactory = IfxInstrumentation.CreateMetricsFactory(
                        monitoringConfiguration.MdmAccount,
                        monitoringConfiguration.MdmNamespace,
                        monitoringConfiguration.Environment,
                        monitoringConfiguration.Tenant,
                        monitoringConfiguration.Role,
                        monitoringConfiguration.RoleInstance);

                    ServiceRuntime.RegisterServiceAsync(
                        "RingMasterWatchdog",
                        serviceContext => new RingMasterWatchdog(serviceContext, metricsFactory)).Wait();
                    RingMasterWatchdogEventSource.Log.RegisterServiceSucceeded();

                    Thread.Sleep(Timeout.Infinite);
                }
                catch (Exception ex)
                {
                    RingMasterWatchdogEventSource.Log.RegisterServiceFailed(ex.ToString());
                    throw;
                }
            }
        }
Exemplo n.º 6
0
        public static void TestRingMasterRingSetup(TestContext context)
        {
            log = s => context.WriteLine(s);

            LogFileEventTracing.Start(Path.Combine(Environment.CurrentDirectory, "TestLogs"));
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Backend-RingMasterEvents", EventLevel.Warning, "RingMasterBackendCore");
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Persistence", EventLevel.Informational, "Persistence");
            LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-Persistence-InMemory", EventLevel.Informational, "InMemoryPersistence");
            Trace.Listeners.Add(new LogFileTraceListener());

            AppDomain.CurrentDomain.ProcessExit +=
                (sender, eventArgs) =>
            {
                LogFileEventTracing.Stop();
            };
        }
Exemplo n.º 7
0
        /// <summary>
        /// This is the entry point of the service host process.
        /// </summary>
        private static void Main()
        {
            VegaDistributedTestService vegaDistributedTestService = null;

            try
            {
                var path    = Assembly.GetExecutingAssembly().Location;
                var builder = new ConfigurationBuilder().SetBasePath(Path.GetDirectoryName(path)).AddJsonFile("appSettings.json");
                appSettings = builder.Build();

                var tenantName = GetClusterNameFromMsa().GetAwaiter().GetResult();

                var nodeName = FabricRuntime.GetNodeContext().NodeName;

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    var errorContext = default(ErrorContext);

                    var defaultDimensions = new Dictionary <string, string>
                    {
                        { "Tenant", tenantName },
                        { "Node", nodeName },
                    };

                    if (!DefaultConfiguration.SetDefaultDimensionNamesValues(
                            ref errorContext,
                            (uint)defaultDimensions.Count,
                            defaultDimensions.Keys.ToArray(),
                            defaultDimensions.Values.ToArray()))
                    {
                        VegaDistTestEventSource.Log.SetMdmDimensionFailed(errorContext.ErrorCode, errorContext.ErrorMessage);
                    }
                }

                // Ensure the event source is loaded
                Assembly.GetAssembly(typeof(ITestJob))
                .GetType("Microsoft.Vega.DistributedTest.VegaDistTestEventSource")
                ?.GetProperty("Log")
                ?.GetValue(null);

                LogFileEventTracing.Start(Path.Combine(appSettings["LogFolder"], "VegaDistributedTestService.LogPath"));
                Trace.Listeners.Add(new LogFileTraceListener());
                LogFileEventTracing.AddEventSource("Microsoft-Azure-Networking-Infrastructure-RingMaster-DistributedTestService");

                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                AppDomain.CurrentDomain.ProcessExit        +=
                    (sender, eventArgs) =>
                {
                    LogFileEventTracing.Stop();
                };

                // The ServiceManifest.XML file defines one or more service type names.
                // Registering a service maps a service type name to a .NET type.
                // When Service Fabric creates an instance of this service type,
                // an instance of the class is created in this host process.
                ServiceRuntime.RegisterServiceAsync(
                    "VegaDistTestSvc",
                    context => vegaDistributedTestService = new VegaDistributedTestService(context))
                .GetAwaiter()
                .GetResult();

                VegaDistTestEventSource.Log.RegisterServiceSucceeded();

                // Prevents this host process from terminating so services keep running.
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                VegaDistTestEventSource.Log.RegisterServiceFailed(ex.ToString());
                throw;
            }
            finally
            {
                if (vegaDistributedTestService != null)
                {
                    vegaDistributedTestService.Dispose();
                }
            }
        }