all groups > dotnet clr > june 2006 >
You're in the

dotnet clr

group:

Boosting priority of an application for a performance unit test


Boosting priority of an application for a performance unit test Matt Adamson
6/29/2006 2:12:19 PM
dotnet clr:
I've created some simple performance tests within the NUnit test framework
to test the performance of various core business object calls e.g. creating
invoices / purchase orders e.t.c. and updating them. The tests basically
need to assert that the time to say create 1000 documents is less than a
configurable amount set by the machine through the app.config file. e.g. 500
ms.

Obviously other processes running may effect the timing slightly so I'd like
to minimise this as much as possible whilst the tests are executing. Would
using the following be appropriate here.

1) Process.PriorityBoostEnabled property
2) Process.PriorityClass
3) Thread.Priority.

The intention would be to change the priority in a method which is run
before all unit test methods are executed and then revert back to the old
behaviour when this is finished.

Thoughts?


Re: Boosting priority of an application for a performance unit test Greg Young
6/30/2006 4:15:25 PM
Boosting your priority will work (I believe through all of those means) but
there will still be things that take priority over you (such as device
drivers).

I am however curious why you are creating "unit tests" for these items as
they are not really unit tests. The fact that you are needing to elevate
your process privilege shows the issue with this type of test being a unit
test. Performance tests as these should only be run in a controlled
environment where the contract would hold true (what happens if I as a
developer choose to run on a pentium 200). As an example you mention that it
should be able to create 1000 documents in x seconds ... That X seconds is
highly dependent upon the environment it is being run on.

The other problem with these types of tests is that they tend to take a
significant amount of time. Because running a single test is fairly
innacurate we often run 1000 or more iterations. By making these items unit
tests we unnecesarily add to the code-test cycle time which is what you want
to be minimal (increased productivity)

The generally accepted way of doing performance tests is to have a machine
that specifically runs the tests (and nothing else). Generally this machine
is vanilla as possible and has nothing else running on it (in an ideal
world). Integration/performance tests are then run periodically run on this
machine (often times nightly depending on system size).

HTH

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung


[quoted text, click to view]

Re: Boosting priority of an application for a performance unit test Greg Young
7/2/2006 1:41:18 PM
This will kill your developer performance to have developers running these
tests. Let's say your average test takes 3 seconds and you have 100
performance tests ... your unit tests will now take 5 minutes to run this
obviously kills your cycle time. The result is that developers will not run
the tests.

Running tests like these is a fairly controlled environment (i.e. running
nightly on your CI server) makes alot more sense.

You bring up another point that makes things difficult in that you are also
integrating with other processes (whatever SQL Server you happen to be
using). Is this server running on the same machine (if not you are likely
testing network latency). What about the load of this server during ther
testing period (i.e. scheduled jobs).

The way I do this is I have a set of performance tests which are run on an
integration server (my integration server does almost nothing at night, i.e.
scheduled jobs etc so it is a good place to run tests). I have thresholds
setup for an allowable delta due to outside variables. If this threshold is
crossed it will generate an error report.

Cheers,

Greg

[quoted text, click to view]

Re: Boosting priority of an application for a performance unit test Matt Adamson
7/2/2006 2:07:05 PM
Thanks for your thoughts Greg

I have created unit tests for the sole purpose of attempting to catch
developers

a) Making database modifications e.g. creating triggers, indexes, which
would slow the creation of say invoices down by an unacceptable margin e.g.
20%. I could quite easily imagine a developer creating a complex trigger and
inadvertently not thinking about creation time.
b) Making code modifications to the say invoice business object to add a
complex business rule which slowed creation down by 50%.

Obviously if an existing client is getting 10000 invoices imported in a 1
hour time window and they only have 1 hour 20 minutes say, if a patch was
applied was increased this to 1 hours 30 minutes they may have a serious
issue.

By adding the performance test of creating x documents in y seconds I have
tried to encompass a test which would break the cruise control build if the
performance went to an unacceptable margin. I appreciate each machine will
have a completely different time which is why I made the timings
configurable e.g. the config file of the unit test assembly has entries

<add key="SP_PERF_PO_1-MaxTimeMs" value="400" />
<add key="SP_PERF_PO_2-MaxTimeMs" value="600" />

This file will be managed in VSS so if any developers have to increase the
time to get it to pass on our build server, we have full history of this.
The unit tests create a large selection of docs e.g. 1000 so should see any
inconsistensies in times.

I am therefore hoping the various raises of elevating process / thread
priority here would help bring about a bit more consistency to my results
and ensure the unit tests don't fail unexpectedly because of other factors
on the machine.

Thoughts?


[quoted text, click to view]

Re: Boosting priority of an application for a performance unit test Greg Young
7/2/2006 6:22:16 PM
I am saying you probably shouldn't do this but that I believe all mechanisms
would work (the thread priority probably being the best method as you can
spawn the tests on a new thread and only grant that thread higher priority).
The problem with boosting your priority is that there are still things at a
higher priority so it is only one step towards making things more
deterministic.

Cheers,

Greg


[quoted text, click to view]
Re: Boosting priority of an application for a performance unit test Matt Adamson
7/2/2006 10:34:11 PM
All unit tests are forced to be run by the CI server ( Cruise Control .NET )
and taking an extra 5 minutes or so to run additional performance is not an
issue for us. I would rather spend the 5 minutes rather than risk getting
slower performant code released to our clients.

However currently our unit tests are executed after any code changes are
detected in VSS. In light of what you say though I think it would be better
to schedule these tests to not run on every build but only at a scheduled
time e.g. 1 in the morning. As the server is used by others for a source
control repository, it can be utilised at random times.

I appreciate your thoughts however you haven't answered my question on the
way to boost the priority of processes using the 3 methods mentioned, or are
you saying you should never do this?

Cheers

Matt

[quoted text, click to view]
AddThis Social Bookmark Button