Monday, 11 March 2013

How PBKDF2 interactions affected UnitTests performance by 2.5x

With PBKDF2 support enabled all the time: 1min 20sec

image

With PBKDF2 only set for the test that test its effectiveness: 35sec

image

The difference is the highlighted line below (first in the SetupDatabase method)

image

That is an extension method that sets the DEFAULT_PBKDF2_INTERACTIONS value

image

which is used to create the hash value for the user’s password

image

The reason this simple change makes a massive difference is because most TeamMentor server-side unit tests use a in-memory database (with at least one admin user), with some tests creating new users in order to perform specific tests.

For example, the test:

image

will create 3 users and execute in about 4 sec with 1 DEFAULT_PBKDF2_INTERACTIONS

image

and in 5 sec with 20000 DEFAULT_PBKDF2_INTERACTIONS  (which is the default value when TM is running)

image

Why the 1sec delay?

At the moment the PBKDF2 value was chosen so that the calculation value takes between 200ms and 400ms (to give us security without a big performance impact)

Which means that this UnitTest will create 3 users which will run the PBKDF2 calculation 3 times (once per user)
Post a Comment