簡體   English   中英

Web服務性能

[英]Webservice Performance

我有幾個在IIS 7上運行的負載平衡應用程序服務器。我需要檢查從每個服務器進行了多少次Web服務調用。 我還需要在特定情況下檢查此情況。 .net中是否有某些東西可以與服務器通信,並在特定實例下為我提供快照。 謝謝

您可以使用Perfmon添加有關呼叫次數的統計信息。 完成此操作后,您還可以添加計時數據...然后,您可以在本地框中使用Perfmon或通過任意數量的工具遠程連接到它。

抱歉,我無法為您提供具體信息-我只看到它完成了,而我自己還沒有完成:)但我認為這非常簡單。

還有一些示例代碼,展示了如何實現性能計數器:

using System;
using System.Configuration;
using System.Diagnostics;
namespace TEST
{
    // sample implementation
    public static class PerformanceHelper
    {
        // update a performance counter value
        public static void UpdateCounter(string WebMethodName, int count)
        {
            // to be able to turn the monitoring on or off
            if (ConfigurationManager.AppSettings["PerformanceMonitor"].ToUpper() == "TRUE")
            {
                PerformanceCounter counter;
                if (!PerformanceCounterCategory.Exists("SAMPLE"))
                {
                    CounterCreationDataCollection listCounters = new CounterCreationDataCollection();
                    CounterCreationData newCounter = new CounterCreationData(WebMethodName, WebMethodName, PerformanceCounterType.NumberOfItems64);
                    listCounters.Add(newCounter);
                    PerformanceCounterCategory.Create("SAMPLE", "DESCRIPTION", new PerformanceCounterCategoryType(), listCounters);
                }
                else
                {
                    if (!PerformanceCounterCategory.CounterExists(WebMethodName, "SAMPLE"))
                    {
                        CounterCreationDataCollection rebuildCounterList = new CounterCreationDataCollection();
                        CounterCreationData newCounter = new CounterCreationData(WebMethodName, WebMethodName, PerformanceCounterType.NumberOfItems64);
                        rebuildCounterList.Add(newCounter);
                        PerformanceCounterCategory category = new PerformanceCounterCategory("SAMPLE");
                        foreach (var item in category.GetCounters())
                        {
                            CounterCreationData existingCounter = new CounterCreationData(item.CounterName, item.CounterName, item.CounterType);
                            rebuildCounterList.Add(existingCounter);
                        }
                        PerformanceCounterCategory.Delete("SAMPLE");
                        PerformanceCounterCategory.Create("SAMPLE", "DESCRIPTION", new PerformanceCounterCategoryType(), rebuildCounterList);
                    }
                }
                counter = new PerformanceCounter("SAMPLE", WebMethodName, false);
                if (count == -1)
                    counter.IncrementBy(-1);
                else
                    counter.IncrementBy(count);
            }
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM