Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance metrics on specific routines: any best practices?

I'd like to gather metrics on specific routines of my code to see where I can best optimize. Let's take a simple example and say that I have a "Class" database with multiple "Students." Let's say the current code calls the database for every student instead of grabbing them all at once in a batch. I'd like to see how long each trip to the database takes for every student row.

This is in C#, but I think it applies everywhere. Usually when I get curious as to a specific routine's performance, I'll create a DateTime object before it runs, run the routine, and then create another DateTime object after the call and take the milliseconds difference between the two to see how long it runs. Usually I just output this in the page's trace...so it's a bit lo-fi. Any best practices for this? I thought about being able to put the web app into some "diagnostic" mode and doing verbose logging/event log writing with whatever I'm after, but I wanted to see if the stackoverflow hive mind has a better idea.

like image 227
Chris Avatar asked Nov 13 '08 15:11

Chris


People also ask

What are the three types of performance metrics?

Graphic rating scales, management by objectives and forced ranking are three methods used to measure employee performance.

What is an example of a performance metric?

There are many different forms of performance metrics, including sales, profit, return on investment, customer happiness, customer reviews, personal reviews, overall quality, and reputation in a marketplace.


1 Answers

For database queries, you have a two small problems. Cache: data cache and statement cache.

If you run the query once, the statement is parsed, prepared, bound and executed. Data is fetched from files into cache.

When you execute the query a second time, the cache is used, and performance is often much, much better.

Which is the "real" performance number? First one or second one? Some folks say "worst case" is the real number, and we have to optimize that. Others say "typical case" and run the query twice, ignoring the first one. Others says "average" and run in 30 times, averaging them all. Other say "typical average", run the 31 times and average the last 30.

I suggest that the "last 30 of 31" is the most meaningful DB performance number. Don't sweat the things you can't control (parse, prepare, bind) times. Sweat the stuff you can control -- data structures, I/O loading, indexes, etc.

like image 129
S.Lott Avatar answered Oct 07 '22 15:10

S.Lott