perfmon interview questions
Top perfmon frequently asked interview questions
In our application, we are using the Windows Performance Counters to store some of our application metrics, which are later retrieved in some web services.
I'm having an issue with the amount of time it takes to read the value from the counters. I've looked through the rest of my app and everything is fine, performance wise, but reading from the counters within a loop (from List or array) takes a painful amount of time.
Example code:
// This triggers a read of the counter's initial value (1000ms delay following for calculated counters)
counters.ToList().ForEach(counter => counter.NextValue());
In my testing of just the loop above, a list of 1,359 counters takes 20 seconds, and with a stopwatch in place, it seems the average time to read a counter value is either 0-10ms, or about 80-90ms. A lot of them take 0ms, the highest being about 170ms, with the average non-zero being about 80-90ms.
Maybe I am being too optimistic, but I would have figured that reading 1,000 numeric values should take only a few milliseconds. Is there a lot more processing going on here than I'm aware of?
I actually have another loop later in my logic that gets a second value for calculated counters. That just makes this doubly worse. :)
Thanks!
Update 1
I wrapped the counter retrieval in a stopwatch and I'm surprised by the results. Reading even the simple property of .RawValue
still takes an excessive amount of time. It's my understanding that counters all basically work the same, and retrieval should be incredibly fast; strangely I'm also seeing a pattern where counters for Networking categories take longer.
According to http://joe.blog.freemansoft.com/2014/03/windows-performance-counters.html, performance for the Performance Counter service shouldn't even be a consideration.
I've posted some stopwatch results to the following pastebin: http://pastebin.com/raw.php?i=aDJk2Tru
My code is as follows:
Stopwatch t;
foreach (var c in counters)
{
t = Stopwatch.StartNew();
var r = c.RawValue;
Debug.WriteLine(t.ElapsedMilliseconds.ToString("000") + " - " + c.CategoryName + ":" + c.CounterName + "(" + c.CounterType + ") = " + r);
}
As you can see in the paste, a lot of reads are 0, but there are a lot in the 50-100ms range. I don't really understand how that can be. Surely one counter value should be just as fast as any other, right?
Source: (StackOverflow)
We have a WCF service with multiple TCP endpoints. I am interested in monitoring the total number of concurrent open connections at any given time. Are there any perfmon counters that will allow us to do this out of the box? Note that number of instances != number of connections in our case.
Source: (StackOverflow)
I would like to use PerfMon.exe to monitor the calls to a WCF service, but I don't understand which counter I have to use. I tried Calls and Instance but the result is always 0.
Could you explain me the meaning of counters?
Moreover, there are 3 groups of counters:
- ServiceModelEndpoint
- ServiceModelOperation
- ServiceModelService
What is their meaning?
Thank you in advance.
Source: (StackOverflow)
I have created a .coverage
file using Vsperfmon.exe
I am currently using VS 2012 professional for web
licensed edition. The .coverage
result cannot be opened in VS Professional
. After Googling I have come to know that VS Ultimate
can open it
Rather than using VS Ultimate
, is there any plugins for VS professional 2012
or any 3rd party solutions
Source: (StackOverflow)
$timeout = new-timespan -Minutes 1
$sw = [diagnostics.stopwatch]::StartNew()
$path = "d:\powershell\test.csv"
"Processor Load, Available Memory(MB), Max Memory(Bytes)" >> $path
while ($sw.elapsed -lt $timeout)
{
$a = gwmi -query "Select * from win32_processor"
$b = gwmi -query "Select * from win32_perfrawdata_perfOS_memory"
$c = gwmi -query "Select * from win32_physicalmemory"
$date = Get-Date -format s
$a.loadpercentage + "," + $b.availableMbytes + "," + $c.capacity >> $path
start-sleep -seconds 5
}
So I'm just looking to get a minute long snapshot of what's going on. I'm not just opening this in perfmon for reasons. Basically I'd expect to get a comma-delimited output in the CSV file mentioned. It works for a single variable, but when I try to add a second variable, or text I get the following error.
Cannot convert value ", test" to type "System.Int32". Error: "Input string was not in a
correct format."
At D:\powershell\VDIPerfMon.ps1:14 char:21
+ $a.loadpercentage + <<<< ", test" >> $path
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
How can I fix this problem?
Source: (StackOverflow)
I have recently been becoming acquainted with perfmon and with xperf. Perfmon uses performance counters and xperf uses ETW (event tracing for windows). Perfmon has objects that provide data, whereas xperf uses groups of "providers". As a newbie into this area I am asking whether anyone could tell me whether the performance counters used by perfmon are really based on the same thing under the hood as the ETW events used by xperf and if so, could you make the connection clear. If they aren't based on the same thing, could you explain how they are different?
Source: (StackOverflow)
I have an ASP.Net 3.5 website running in IIS 6 on Windows Server 2003 R2. It is a relatively small internal application that probably serves less than ten users at any given time. The server has 4 Gig of memory and shows that 3+ Gig is available while the site is active.
Just minutes after restarting the web application Performance monitor shows that there is a whopping 4,294,967,293 sessions active! I am fairly certain that this number is incorrect; at the time this reading there were only 100 requests to the website.
Has anyone else experienced this kind odd behavior from perf mon? Any ideas on how to get an accurate reading?
UPDATE: After running for about an hour the number of active sessions has dropped by 4. So it does seem to be responding to sessions timing out.
Source: (StackOverflow)
We use output caching profiles in Web.Config like so:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<clear />
<add name="CacheHourly" location="Server" duration="3600" varyByParam="*" varyByCustom="IsMobile" />
<add name="CacheDaily" location="Server" duration="86400" varyByParam="*" varyByCustom="IsMobile" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
In perfmon
, we're seeing 100% misses (no hits) in Output Cache counters. We're basically seeing 0s across the board for Output Cache counters (except misses).
See screenshot below.
The kicker is that I'm fairly sure it's enabled. If I add enabled="false"
to each output cache profile, and then hit a target page, it will return in 300ms consistently. If I keep them enabled, it will return in 90ms consistently, which isn't super fast, but it's consistently faster than 300ms.
Edit: Am I wrong to think that Output Cache * counters are the correct counters? URI Cache counters seem to have higher hit %, but I thought that was just for IIS URI metadata.
Source: (StackOverflow)
I need to create several counters for a system health check and monitoring. Since there are numerous tools for logging, reporting and alerting Windows Perfmon data, I am looking to publish that data as Perfmon counters.
Some of the values need to come from a SQL Server 2008 database, examples of such are the number of records in a table used as a queue, and the age of the oldest record in the table. While it looks like this can be accomplished by using a SQL Server, User Settable Object and the stored procedures sp_user_counter1
to sp_user_counter10
this limits me to only 10 counters per server and the counter names and descriptions cannot be customized to reflect what the counter is.
Without creating our own application to create the Perfmon counters, are there any other ways to create counters in SQL Server? If not, are there any tools/projects that allow for the creation of custom counters using SQL queries?
Source: (StackOverflow)
Hi I am trying to to create a custom performance counter for use in perfmon. The following code works pretty well, however I have one problem..
With this solution I have a timer updating the value of the performance counter, however I would like to not have to run this executable to get the data I need. That is I would like to just be able to install the counter as a one time thing and then have perfmon query for the data (as it does with all the pre-installed counters).
How can I achieve this?
using System;
using System.Diagnostics;
using System.Net.NetworkInformation;
namespace PerfCounter
{
class PerfCounter
{
private const String categoryName = "Custom category";
private const String counterName = "Total bytes received";
private const String categoryHelp = "A category for custom performance counters";
private const String counterHelp = "Total bytes received on network interface";
private const String lanName = "Local Area Connection"; // change this to match your network connection
private const int sampleRateInMillis = 1000;
private const int numberofSamples = 100;
private static NetworkInterface lan = null;
private static PerformanceCounter perfCounter;
static void Main(string[] args)
{
setupLAN();
setupCategory();
createCounters();
updatePerfCounters();
}
private static void setupCategory()
{
if (!PerformanceCounterCategory.Exists(categoryName))
{
CounterCreationDataCollection counterCreationDataCollection = new CounterCreationDataCollection();
CounterCreationData totalBytesReceived = new CounterCreationData();
totalBytesReceived.CounterType = PerformanceCounterType.NumberOfItems64;
totalBytesReceived.CounterName = counterName;
counterCreationDataCollection.Add(totalBytesReceived);
PerformanceCounterCategory.Create(categoryName, categoryHelp, PerformanceCounterCategoryType.MultiInstance, counterCreationDataCollection);
}
else
Console.WriteLine("Category {0} exists", categoryName);
}
private static void createCounters() {
perfCounter = new PerformanceCounter(categoryName, counterName, false);
perfCounter.RawValue = getTotalBytesReceived();
}
private static long getTotalBytesReceived()
{
return lan.GetIPv4Statistics().BytesReceived;
}
private static void setupLAN()
{
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in interfaces)
{
if (networkInterface.Name.Equals(lanName))
lan = networkInterface;
}
}
private static void updatePerfCounters()
{
for (int i = 0; i < numberofSamples; i++)
{
perfCounter.RawValue = getTotalBytesReceived();
Console.WriteLine("perfCounter.RawValue = {0}", perfCounter.RawValue);
System.Threading.Thread.Sleep(sampleRateInMillis);
}
}
}
}
Source: (StackOverflow)
I want to access the "Processor Time %" counter in an application which runs on systems with different localizations.
To do so, I want to access the counter by its index, which is guaranteed to be unique (see https://support.microsoft.com/en-us/kb/287159).
The following code works and gives me the correct result for the current locale, but to open the performance counter I also need the counter's category name (see constructors for the PerformanceCounter
class) as well as the instance name:
[DllImport("pdh.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, StringBuilder szNameBuffer, ref uint pcchNameBufferSize);
void Main()
{
var buffer = new StringBuilder(1024);
var bufSize = (uint)buffer.Capacity;
PdhLookupPerfNameByIndex(null, 6, buffer, ref bufSize);
Console.WriteLine(buffer.ToString());
var counter = new PerformanceCounter(/* category??? */, buffer.ToString(), /* instance??? */);
}
How can I get that category and instance name?
See also:
Retrieve performance counter value in a language-independent way, which describes the same problem but does not provide a solution.
Source: (StackOverflow)
Hey all,
I'm having trouble with PerfMon on one system out of fifteen in a development environment. Accessing it from the local machine is fine but connecting to it remotely throws a "Cannot connect" error.
Each machine is running Win 2003, is connected to the same domain and I have admin rights to all.
There were some services set to disabled which are normally enabled by default so I've set these to match the other machines on the network - still have the same problem.
Any ideas?
Cheers
**Update**
Ok - I found it was the remote registry service not running correctly causing the above error; Once that was enabled Perfmon is now telling me "No such interface supported".
If I connect through Computer Management, it fails the first time, but the second attempt is successful. Connecting through perfmon fails everytime.
Source: (StackOverflow)
We have a 3-tier application with a C# client, a C# WCF web service layer, and a SQL Server database. The web service connects to the database with ADO.NET. All of our C# code is using the .NET Framework 2.0.
Recently, a customer performed a stress test on our application. During the test, the web server generated a lot of errors like the following:
Could not connect to database for connection string '...'. Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
I am aware there are ways to catch connection errors when the connection pool is full and try acquiring a connection outside of the connection pool. We also found several queries that needed to be tuned, but they dot not explain web server connection timeouts.
We're trying to figure out why the web server was timing out connecting to the database. I have setup the web server to enable all of the ADO.NET performance counters. However, I don't see anything related to the times required to connect or connection timeouts or the like. Ideally, we would be able to graph the connection times in perfmon
next to the other ADO.NET counters.
Is there a way to monitor the ADO.NET performance in acquiring connections?
I imagine we could create our own "average connection open time" performance counter by timing attempts to open connections, but I'd rather use something that already exists.
Source: (StackOverflow)
When I try to run this code:
var categories = System.Diagnostics.PerformanceCounterCategory.GetCategories();
I get an ArgumentException exception.
I already tried the following with no luck:
- How to manually rebuild Performance Counter Library
http://support.microsoft.com/kb/300956
- lodctr /R
- Logged in as a local administrator.
- Disabled User Access Control (UAC)
- Made my user member of the Performance Monitor Users group.
I get the same result whether I run Visual Studio 2008, 2010 or 2012, on a Windows 7 Enterprise SP1 64-bit computer.
I will appreciate any help.
Thank you.
Source: (StackOverflow)
I wanted to simulate memory leak in my application. I write following code, and tried to see in perfmon.
int main()
{
int *i;
while(1)
{
i = (int *) malloc(1000);
//just to avoid lazy allocation
*i = 100;
if(i == NULL)
{
printf("Memory Not Allocated\n");
}
Sleep(1000);
}
}
When I see used memory in Task Manager, it is fluctuate between 52K and 136K, but not going beyond that. Means, somethings it shows 52K and sometimes 136K, I do not understand how this code once goes to 136K, coming back to 52K, and not going beyond that.
I tried to use perfmon, but not able to exactly what to see in perfmon, snapshot of counters,
Please suggest how to simulate memory leak and how to detect it.
Source: (StackOverflow)